我在使用 PatPeter 的基于 SQL 的 Bukkit 插件上遇到了一个相当大的错误。的SQLite Bukkit plugin “SQL 库”。我正在尝试使用 the first solution from another SO thread 确定玩家是否已输入数据库。 。更多信息可参见this forum thread ,但我也会在这里给出一个简短的概述。
这是堆栈跟踪:
这是可疑的方法,堆栈跟踪中指示的行被标记为:
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;
}
这是怎么回事?
最佳答案
我从未亲自使用过 SQLite,但我想说您可能错误配置了 SQLite 设置 onEnable()
,因为 sqlite.getConnection()
必须返回 null
。尝试在第 109 行之前添加以下代码:
if(connection == null) {
throw new RuntimeException("SQLite connection is null!");
}
如果您在下次运行它时收到 RuntimeException,您可能应该检查您的 SQLite 设置。
关于java - SQLite - Bukkit 插件中的奇怪 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13994371/