“java.sql.SQLException: ResultSet is not updatable” with JdbcRowSet

▼魔方 西西 提交于 2019-12-02 10:27:22

问题


I want to use RowSet Interface implement update,But I meet some error.

I’ve tried on following code:

// Load the JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver loaded");

RowSetFactory rsFactory = RowSetProvider.newFactory();
JdbcRowSet rowSet = rsFactory.createJdbcRowSet();

rowSet.setUrl(DATABASE_URL);
rowSet.setUsername(USERNAME);
rowSet.setPassword(PASSWORD);

// make rowset updateable
rowSet.setReadOnly(false); 
rowSet.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE);

rowSet.setCommand("Select * from money");
rowSet.execute();

rowSet.absolute(3);
rowSet.updateInt("balance", parseIntBalance); //update third rows balance label to 5000
rowSet.updateRow();

Following is error message:

java.sql.SQLException: ResultSet is not updatable
    at com.sun.rowset.JdbcRowSetImpl.checkTypeConcurrency(JdbcRowSetImpl.java:4139)
    at com.sun.rowset.JdbcRowSetImpl.updateInt(JdbcRowSetImpl.java:2306)
    at com.sun.rowset.JdbcRowSetImpl.updateInt(JdbcRowSetImpl.java:2735)

来源:https://stackoverflow.com/questions/56090869/java-sql-sqlexception-resultset-is-not-updatable-with-jdbcrowset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!