updateLong not allowed in ResultSet

前端 未结 3 862
醉酒成梦
醉酒成梦 2020-12-20 01:22

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 =          


        
相关标签:
3条回答
  • 2020-12-20 02:08

    As per javadoc

    static final int TYPE_SCROLL_SENSITIVE
    

    The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet.

    What you are looking for might be:

    static final int TYPE_SCROLL_INSENSITIVE
    

    The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet.

    0 讨论(0)
  • 2020-12-20 02:14

    According to the Derby Documentation, a query with an ORDER BY is not updatable:

    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.

    In other words you can't include the ORDER BY, but that would defeat your purpose (as you seem to be renumbering some identifier).

    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 also does not support TYPE_SCROLL_SENSITIVE result sets. According to the documentation, Derby supports both:

    • TYPE_FORWARD_ONLY and
    • TYPE_SCROLL_INSENSITIVE

    Note that your current code doesn't require TYPE_SCROLL_INSENSITIVE because you are only processing it as a forward only.

    0 讨论(0)
  • 2020-12-20 02:19

    Not sure what your particular flavor of SQL is, but how about doing it in a single update statements instead of a read+update, something like this:

    UPDATE Sometable
    SET col1 =
    (SELECT COUNT(*)
    FROM Sometable AS S
    WHERE keycol <= Sometable.keycol)
    
    0 讨论(0)
提交回复
热议问题