同じコードに関連する 2 つの質問があります。
CachedRowSet cachedRow = new CachedRowSetImpl();
cachedRow.setUrl("jdbc:mysql://localhost:3306/test");
cachedRow.setUsername("root");
cachedRow.setPassword("StackOverKindOfThing");
cachedRow.setCommand("SELECT * FROM books");
cachedRow.execute();
int [] arrayKey = {1};
//cachedRow.setKeyColumns(arrayKey); // I can even omit this line and it works anyway;
cachedRow.next();
cachedRow.updateString(2, "ball");
cachedRow.updateRow();
cachedRow.acceptChanges();//it works with cachedRow.acceptChanges(con) where con
//has been initialized and has been set on setAutoCommit(false);
これは、.setUrl("url"); で設定された CachedRowSet を使用して取得している例外です。
at CachedThingSet.main(CachedThingSet.java:31)
javax.sql.rowset.spi.SyncProviderException: Can't call commit when autocommit=true
1)チュートリアルでは不可能と書かれているのに、データベースにデータを挿入できる理由を知りたいです(setKeyColumn()
メソッドはコメントアウトされています):
キー列の設定
crs オブジェクトを更新し、それらの更新をデータベースに保存する場合は、キー列というもう 1 つの情報を設定する必要があります。
そして、 (行を更新する)をautocommit(false)
使用するためにとの接続を設定する必要があるのはなぜ
ですか。それ以外の場合は、CachedRowSet
SyncProviderException: can't call commit when autocommit=true
setUrl("url");
acceptChanges(con)
autocommit(false)