我尝试使用prepareStatement查询sqlite,但遇到了异常:
java.sql.SQLException: not supported by PreparedStatment
at org.sqlite.PrepStmt.unused(PrepStmt.java:328)
at org.sqlite.PrepStmt.executeUpdate(PrepStmt.java:314)
我正在使用Eclipse开发我的程序,所以当我点击 at org.sqlite.PrepStmt.unused(PrepStmt.java:328)
时,它会将我重定向到 PrepStmt.class
,在其中我找到了以下内容:
@Override
public int executeUpdate(String sql) throws SQLException {
throw unused();
}
private SQLException unused() {
return new SQLException("not supported by PreparedStatment");
}
这是我的代码:
public static void deleteOp(String word) throws Exception {
Connection c = null;
PreparedStatement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection(connectionString);
c.setAutoCommit(false);
System.out.println("Opened database successfully");
String sql = "DELETE from " + tableName + " where WORD = ? ;";
System.out.println(sql);
stmt = c.prepareStatement(sql);
stmt.clearParameters();
stmt.setString(1, word);
stmt.executeUpdate(sql);
c.commit();
stmt.close();
c.close();
} catch ( Exception e ) {
throw e;
}
System.out.println("Operation done successfully");
}
我想知道我的代码有问题还是Sqlite根本不支持prepareStatement,或者我的驱动程序存在问题(例如由于过时)?