无法使用 Oracle 数据库更新 JDBC RowSet
我需要更新 RowSet 中的一些行,但是当我尝试执行此操作时,出现不可更新的异常。为什么?
JdbcRowSet rs = new oracle.jdbc.rowset.OracleJDBCRowSet(con);
rs.setCommand("SELECT status FROM s");
rs.setUrl("jdbc:oracle:thin:@localhost:1521:orcl");
rs.setUsername("username");
rs.setPassword("password");
rs.setReadOnly(false);
rs.execute();
// this doesn't work
rs.last();
rs.deleteRow();
// this doesn't work too
rs.absolute(2);
rs.updateInt("status", 10);
rs.updateRow();
I need to update some rows in a RowSet, but when I'm trying to do that I get an not updateable Exception. Why?
JdbcRowSet rs = new oracle.jdbc.rowset.OracleJDBCRowSet(con);
rs.setCommand("SELECT status FROM s");
rs.setUrl("jdbc:oracle:thin:@localhost:1521:orcl");
rs.setUsername("username");
rs.setPassword("password");
rs.setReadOnly(false);
rs.execute();
// this doesn't work
rs.last();
rs.deleteRow();
// this doesn't work too
rs.absolute(2);
rs.updateInt("status", 10);
rs.updateRow();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你得到的例外是
或类似的东西。这是我在测试你的代码时看到的。
说实话,我以前没有见过OracleJDBCRowSet 这个类。我不太确定如何修改您的代码来解决您看到的错误。然而,让您的代码看起来更像“传统”JDBC,同时还保留更改 Java 中结果集的能力并不是太困难。您真正需要做的就是向
prepareStatement
方法调用传递两个额外的参数:I imagine the exception you're getting is
or something similar. This was what I saw while testing out your code.
To be honest, I hadn't seen the class OracleJDBCRowSet used before. I wasn't too sure how to modify your code to get around the error you saw. However, it's not too difficult to make your code look more like 'traditional' JDBC whilst also retaining the ability to change the result-set in Java. All you really need to do is to pass an extra two parameters to the
prepareStatement
method call: