在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,因为您只将其作为前向处理.

相关文章

连接数据库的方式:第一种方式:ODBC:开放数据库连接是微软...
JDBCRequest 使用VariableNamesmysql:数据库连接池对象var...
 1.JDBCDBC(JavaDataBaseConnectivity):Java数据库连接技术...
1.需要jar包的支持:java.sqljavax.sqlmysql-conneter-java....
1.简介Activiti是一个业务流程管理(BPM)框架,它是覆盖了业务...
1.JDBC体系系统一组规范:接口JDBC接口(API)包括两个层次:...