在ResultSet中不允许使用java – updateLong
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在ResultSet中不允许使用java – updateLong,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2009字,纯文字阅读大概需要3分钟。
内容图文
![在ResultSet中不允许使用java – updateLong](/upload/InfoBanner/zyjiaocheng/704/6800d76300a344e2951915d494041b4a.jpg)
我想在我的表中添加一个序列号.这是我的方法:
public void reArrangeTrID(){
String parti = name.getText().toUpperCase();
long trid = 1;
try{
String query="SELECT LONGDATE, TRID FROM PARTIACCOUNT WHERE PARTY= '"+parti+"' ORDER BY LONGDATE ASC ";
conn = new connection().db();
stmtt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmtt.executeQuery(query);
while(rs.next()) {
long tr = rs.getLong("TRID");
rs.updateLong("TRID", trid);
rs.updateRow();
trid++;
jLabel9.setText("Arranging transactions... Please wait.");
}
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Unknown Error!! Data cannot be displayed!"+ex);
}
finally{try{stmtt.close(); rs.close(); conn.close(); }catch(SQLException ex){}}
}
为什么这个方法给我一个updateLong不允许的错误,因为ResultSet不是可更新的ResultSet,而我的结果集已经设置为可更新.
我正在使用德比数据库.
解决方法:
根据Derby Documentation,具有ORDER BY的查询不可更新:
Only simple, single-table SELECT cursors can be updatable. The SELECT statement for updatable ResultSets has the same syntax as the SELECT statement for updatable cursors. To generate updatable cursors:
- The
SELECT
statement must not include anORDER BY
clause.- The underlying Query must be a SelectExpression.
- The SelectExpression in the underlying Query must not include:
DISTINCT
- Aggregates
GROUP BY
clauseHAVING
clauseORDER BY
clause- The
FROM
clause in the underlying Query must not have:
- more than one table in its
FROM
clause- anything other than one table name
- SelectExpressions
- subqueries
- If the underlying Query has a
WHERE
clause, theWHERE
clause must not have subqueries.
换句话说,您不能包含ORDER BY,但这会破坏您的目的(因为您似乎正在重新编号某些标识符).
您需要使用某些查询重新编号而不在JDBC中进行处理,或者您需要使用两个Statement对象,一个用于查询行,另一个用于更新它们.
德比也是does not support TYPE_SCROLL_SENSITIVE结果集.根据文档,Derby支持:
> TYPE_FORWARD_ONLY和
> TYPE_SCROLL_INSENSITIVE
请注意,您当前的代码不需要TYPE_SCROLL_INSENSITIVE,因为您只将其作为前向处理.
内容总结
以上是互联网集市为您收集整理的在ResultSet中不允许使用java – updateLong全部内容,希望文章能够帮你解决在ResultSet中不允许使用java – updateLong所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。