gpt4 book ai didi

java - RowSet 未启用写入

转载 作者:行者123 更新时间:2023-11-30 11:52:04 25 4
gpt4 key购买 nike

请帮帮我,我正在尝试更新行集中一列的值,但我不断收到异常......该行集未启用写入。我搜索了很多但没有找到使行集写入启用的方法。在下面提到我正在使用的代码和以下异常:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", uname, pwd);

String query = "select * from " + table;
PreparedStatement preparedStatement = conn.prepareStatement(query);
ResultSet rset = preparedStatement.executeQuery();
OracleCachedRowSet oracleCachedRowSet = new OracleCachedRowSet();
oracleCachedRowSet.populate(rset);
ResultSetMetaData resultSetMetaData = oracleCachedRowSet.getMetaData();
int numberOfColumns = resultSetMetaData.getColumnCount();

while (oracleCachedRowSet.next()) {

oracleCachedRowSet.updateBigDecimal(1, new BigDecimal(99));
oracleCachedRowSet.updateRow();
oracleCachedRowSet.acceptChanges();
for (int i = 1; i <= numberOfColumns; i++) {

System.out.print(oracleCachedRowSet.getString(i) + " ");

}
}
}

执行上述代码时出现异常:

java.sql.SQLException: The RowSet is not write enabled
at oracle.jdbc.rowset.OracleCachedRowSet.checkColumnIndex(OracleCachedRowSet.java:912)
at oracle.jdbc.rowset.OracleCachedRowSet.updateObject(OracleCachedRowSet.java:5931)
at oracle.jdbc.rowset.OracleCachedRowSet.updateBigDecimal(OracleCachedRowSet.java:6430)
at Test.getDBConnection(Test.java:86)
at Test.main(Test.java:37)

最佳答案

尝试设置:

oracleCachedRowSet.setReadOnly(false);

关于java - RowSet 未启用写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7090446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com