我嘗試使用prepareStatement來查詢SQLite的工作,但我遇到一個例外: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,或者我的驅動程序有問題(例如由於過時)?
請參閱幾年前的[此主題](https://groups.google.com/forum/#!topic/xerial/YMIJga6TDmA)。它看起來像SQLite的人知道它,但它不是一個高優先級的問題。 – yshavit