我嘗試將一些數據放在我的H2數據庫中,但是我在數據庫中總是noob,所以它在超過一個小時後拋出錯誤而不是錯誤。 通常我可以修復它,但現在我得到了一個新問題,我嘗試使用 getGeneratedKeys()首先我試圖使用AUTO_INCREMENT(1,1),但這並沒有太多的功能,但它不會工作rigth。h2 getGeneratedKeys拋出異常
我PROGRAMM拋出異常是
org.h2.jdbc.JdbcSQLException:的Funktion 「的getGeneratedKeys」 nicht gefunden 功能 「的getGeneratedKeys」 找不到; SQL語句: INSERT INTO logTbl值(的getGeneratedKeys(),Webservice-> startThread0:Thread0)[90022-173]
一個我的數據庫功能看起來像這樣
public void createTable(String Log) {
try {
Class.forName("org.h2.Driver");
} catch (ClassNotFoundException e) {
System.err.println("TREIBER FEHLER");
e.printStackTrace();
}
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:h2:~/DBtest/Logs");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS logTbl(ID INT PRIMARY KEY, LOG VARCHAR(255))");
//stat.execute("insert into test values(1, 'Hello')");
for (int i = 0; i < 20; i++) {
stat.execute("insert into logTbl values(getGeneratedKeys()," + Log + ")");
}
stat.close();
conn.close();
} catch (SQLException e) {
System.err.println("SQL FEHLER");
e.printStackTrace();
}
}
希望你能幫助我修復我的錯誤,因爲我說我總是新的,只是有一些代碼示例作爲「教程」,因爲我沒有找到一個好的教程
'getGeneratedKeys()'是'PreparedStatement'類的Java方法,它不是** SQL函數,所以你不能在SQL語句中使用它。 [查看JavaDocs](http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#getGeneratedKeys%28%29)和[JDBC教程](http:// docs .oracle.com/javase/6/docs/technotes/guides/jdbc/getstart/statement.html#1000569) –
ohhh ..謝謝:D – alovaros
另請參閱[here](http://stackoverflow.com/a/25214466/330315)和[這裏](http://stackoverflow.com/a/18337542/330315) –