MySQL Problem: PreparedStatement is null after being set

Discussion in 'Plugin Development' started by messageofdeath, Jul 23, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    messageofdeath

    OK so this line of code here is making a null reference once being used.

    Im using PatPeter 's MySQL/SqLite Drivers

    Line 100
    Which is the second line of code in the dialog box below:
    PHP:
    public void addToImplemented() {
        
    PreparedStatement ps Api.getMySQL().prepare("INSERT INTO Quests_Users (Name, ActiveQuest, PendingQuest, CompletedQuests, Quest) VALUES (?,?,?,?,?);");
        try {
            
    ps.setString(1name);
            
    ps.setInt(20);
            
    ps.setInt(30);
            
    ps.setString(4"0");
            
    ps.setString(5"0");
            
    ps.executeUpdate();
        } catch (
    SQLException e) {
            
    e.printStackTrace();
        }
        
    Api.getMySQL().query(ps.toString());
    }
     
  2. Offline

    Mitsugaru

    Is your Api.getMySQL() call returning a null object?
     
  3. Offline

    messageofdeath

    Edit: I can create tables, insert data.

    no this is the code for it
    PHP:
    @SuppressWarnings("static-access")
    public static 
    MySQL getMySQL() {return plugin.mysql;}
     
  4. Offline

    nisovin

    That doesn't really prove anything. Is plugin.mysql null?
     
    Mitsugaru likes this.
  5. Offline

    messageofdeath

    The mysql is this
    PHP:
    public static MySQL mysql;

    then its set here
    PHP:
    mysql = new MySQL(Bukkit.getLogger(), "[RPG]"config.getString("MySQL.Host"),config.getString("MySQL.Port"), config.getString("MySQL.Database"), config.getString("MySQL.User"), config.getString("MySQL.Password"));
     
  6. Offline

    nisovin

    Is it set before addToImplemented is called?

    Try this:

    Code:
    if (Api.getMySQL() == null) System.out.println("OH NOES!");
    Then you'll know.
     
  7. Offline

    messageofdeath

    I figured it out. It was being null. I had it in the onEnable so i would have to go ingame/command fixed now.
     
  8. Offline

    PatPeter

    Glad it's fixed.
     
Thread Status:
Not open for further replies.

Share This Page