在ResultSet中不允许updateLong [英] updateLong not allowed in ResultSet
问题描述
我正在尝试在表格中添加序列号。这是我的方法:
I am trying to add a serial number in my table. Here is my method:
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
,而我的结果集已设置为可更新。
我正在使用德比数据库。
Why this method gives me an error that updateLong not allowed because ResultSet is not an updatable ResultSet
, while my resultset is already set to updatable.
I am using derby database.
推荐答案
根据 Derby Documentation ,带有 ORDER BY
的查询是不可更新:
According to the Derby Documentation, a query with an ORDER BY
is not updatable:
只有简单的单表SELECT游标才可以更新。可更新ResultSets的SELECT语句与可更新游标的SELECT语句具有相同的语法。要生成可更新游标:
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:
-
SELECT
语句不得包含ORDER BY
子句。 - 基础查询必须是SelectExpression。
- 基础查询中的SelectExpression不得包含:
-
DISTINCT
- 聚合
-
GROUP BY
子句 -
HAVING
子句 -
ORDER BY
子句
- 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
- 其<$>中的多个表c $ c> FROM 子句
- 除一个表名以外的任何内容
- SelectExpressions
- 子查询
- more than one table in its
FROM
clause - anything other than one table name
- SelectExpressions
- subqueries
换句话说,您不能包含
ORDER BY
,但这会破坏您的目的(因为您似乎正在重新编号某些标识符)。In other words you can't include the
ORDER BY
, but that would defeat your purpose (as you seem to be renumbering some identifier).您需要使用一些查询重新编号而不在JDBC中进行处理,或者您需要使用两个
Statement
对象,一个用于查询行和另一行来更新它们。You either need to use some query to renumber without processing in JDBC, or you need to use two
Statement
objects, one to query the rows and another to update them.Derby也不支持
TYPE_SCROLL_SENSITIVE
结果集。根据文档,Derby支持:Derby also does not support
TYPE_SCROLL_SENSITIVE
result sets. According to the documentation, Derby supports both:TYPE_FORWARD_ONLY
andTYPE_SCROLL_INSENSITIVE
请注意,您当前的代码不需要
TYPE_SCROLL_INSENSITIVE
,因为您只是将其作为转发处理只有。Note that your current code doesn't require
TYPE_SCROLL_INSENSITIVE
because you are only processing it as a forward only.这篇关于在ResultSet中不允许updateLong的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-