1

I'm running into a pretty big bug on an SQL-based Bukkit plugin that uses PatPeter's SQLite Bukkit plugin "SQLibrary". I'm attempting to determine whether a player is already entered into the database using the first solution from another SO thread. More information can be found on this forum thread, but I'll give a brief outline here as well.

This is the stack trace:

StackTrace

And here is the suspect method, with the line indicated in the stack trace marked:

SQLite sqlite; // Set in plugin.onEnable(), which executes before anything
String QUERY_PLAYEREXISTS = "SELECT playername FROM table WHERE playername = ?";
...
public boolean exists(String name) throws SQLException {
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet resultSet = null;
    boolean exists = false;

    try {
        connection = sqlite.getConnection();
        statement = connection.prepareStatement(QUERY_PLAYEREXISTS); // 109
        statement.setString(1, name.toLowerCase());
        resultSet = statement.executeQuery();
        exists = resultSet.next();
    } finally {
        connection.close();
        statement.close();
        resultSet.close();
    }

    return exists;
}

What's going on here?

Community
  • 1
  • 1
ChaoticWeg
  • 291
  • 2
  • 15

1 Answers1

1

I've never personally used SQLite, yet I would say that you may have misconfigured the SQLite setup onEnable(), because sqlite.getConnection() must be returning null. Try adding the following code before line 109:

if(connection == null) {
   throw new RuntimeException("SQLite connection is null!");
}

If you get a RuntimeException when next running it, you should probably look into your SQLite setup.

Xyene
  • 2,304
  • 20
  • 36
  • Actually, I ended up figuring it out, and I can't remember what the problem was exactly, but essentially I was attempting to use an opening and closing format reserved for another action, such as creating the table or entering data, and not necessarily retrieving from the table. Basically, I was trying to close objects that hadn't been opened in the first place, or something like that. Accepted though, for being the first and only answer. :) Also, onEnable() is a method belonging to the JavaPlugin class, which is specific to Bukkit. But I can see what you meant! :) – ChaoticWeg Jan 05 '13 at 05:34
  • Glad to know you solved it :-) And I know what onEnable is, I make Bukkit plugins too :3 – Xyene Jan 06 '13 at 20:52