0

我有两个与同一段代码相关的问题:

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 对象进行任何更新并希望将这些更新保存在数据库中,则必须再设置一条信息:键列。

以及为什么我必须建立连接才能autocommit(false)使用 a (CachedRowSet更新一行) 否则我会SyncProviderException: can't call commit when autocommit=true 得到setUrl("url");acceptChanges(con)autocommit(false)

4

0 回答 0