我有一个带表的 H2 DB
CREATE TABLE income_expense
(
amount VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
ondate VARCHAR(255) NOT NULL
);
和一些随机数据,如INSERT INTO income_expense VALUES ('10','Something','2015-04-15');
然后我用JDBC连接到这个数据库并尝试通过CachedRowSet进行更新:
public void doUpdate()
{
try
{
Class.forName("org.h2.Driver");
setConnection(
DriverManager.getConnection("jdbc:h2:~/thisdb", "sa", ""));
CachedRowSet crs2 = new CachedRowSetImpl();
crs2.setType(CachedRowSet.TYPE_SCROLL_INSENSITIVE);
crs2.setConcurrency(CachedRowSet.CONCUR_UPDATABLE);
crs2.setCommand(
"SELECT amount, name, ondate FROM income_expense");
crs2.execute(getConnection());
crs2.absolute(1);
crs2.updateString("amount", "22");
crs2.updateString("name" , "33");
crs2.updateString("ondate", "44");
crs2.updateRow();
crs2.acceptChanges();
}
catch (ClassNotFoundException | SQLException e)
{
System.out.println("Error occured." + e);
}
}
此更新失败并显示消息javax.sql.rowset.spi.SyncProviderException: 1 conflict while synchronizing。
我在更新记录时做错了什么?