微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在ResultSet中不允许使用java – updateLong

我想在我的表中添加一个序列号.这是我的方法

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 an ORDER BY clause.
  • The underlying Query must be a SelectExpression.
  • The SelectExpression in the underlying Query must not include:
    • disTINCT
    • Aggregates
    • GROUP BY clause
    • HAVING clause
    • ORDER 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, the WHERE 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,因为您只将其作为前向处理.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐