についての私の研究では準備されたステートメントに関するいくつかのヒントを教えてくれました。ステートメントの自動生成されたキーは、MariaDB 10.x
これまでのコードでは、更新された文と同じ数の行を持つ結果セットのキーが私に与えられています。しかし、私の期待に反して、getInt(1)メソッドはテーブルの自動認識IDを与えませんが、結果セットの終わりまで1から数えて自動計算された値を返します。
何が間違っていますか? com.mysql.jdbcをorg.mariadb.jdbcコネクタとして使用するようにコードを変更し、両方とも最新バージョンに更新しました。
または別のオプションを設定する必要がありますか?
あなたのお手伝いをしていただきありがとうございます。
public void updateFZSetToUsed() {
/*
* Variablendeklaration
*
*/
Connection conn = null;
Statement stmt1 = null, stmt2 = null;
ResultSet rs = null, rs2 = null;
String stmtstr1, stmtstr2;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception WPex) {
System.out.println(WPex);
}
try {
conn = DriverManager.getConnection("jdbc:mysql://"+configVars.getProperty("serverIP")+"/"+configVars.getProperty("db")+"?", configVars.getProperty("usr"), configVars.getProperty("pw"));
stmt2 = conn.createStatement();
stmt2.executeUpdate("UPDATE fz SET fz_used = 1 WHERE fz_id in (SELECT calls_fz FROM calls)", Statement.RETURN_GENERATED_KEYS);
rs2 = stmt2.getGeneratedKeys();
while(rs2 != null && rs2.next()) {
System.out.println(rs2.getInt(1));
}
} catch (SQLException singleStoreExc) {
// handle any errors
System.out.println("updateFZSetToUsed SQLException: " + singleStoreExc.getMessage());
System.out.println("updateFZSetToUsed SQLState: " + singleStoreExc.getSQLState());
System.out.println("updateFZSetToUsed VendorError: " + singleStoreExc.getErrorCode());
return retString;
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx)
{
System.out.println("rsclose fehler");
}
rs = null;
}
if (rs2 != null) {
try {
rs2.close();
} catch (SQLException sqlEx)
{
System.out.println("rs2close fehler");
}
rs2 = null;
}
if (stmt1 != null) {
try {
stmt1.close();
} catch (SQLException sqlEx) {
System.out.println("stmt1cclose fehler");
}
stmt1 = null;
}
if (stmt2 != null) {
try {
stmt2.close();
} catch (SQLException sqlEx) {
System.out.println("stmt2cclose fehler");
}
stmt2 = null;
}
if (stmt2 != null) {
try {
stmt2.close();
} catch (SQLException sqlEx) {
System.out.println("stmt2cclose fehler");
}
stmt2 = null;
}
if (conn != null) {
try {
conn.close();
}
catch (SQLException sqlEx) {
System.out.println("conn close() Error "+sqlEx);
}
}
}
}
お返事ありがとうございます。私はすぐに解決策が必要だったので、私は問題を解決するための工夫をしました。 (私が覚えている限り、2つの異なるクエリ) 実際にはあなたが記述したようです:id値はINSERT文によってのみ返されます。たぶん、私の記憶は、PHPからmysqlI-XXXコマンド仕様を呼び出そうとしたときに、その細部に私を騙したかもしれません。 もう一度、入力いただきありがとうございます。私はそれを感謝します。 – DigitalDude