× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Updating result set in Java
  • From: "Xu, Weining" <Weining.Xu@xxxxxxx>
  • Date: Fri, 2 Feb 2001 15:29:04 -0500

Title: Updating result set in Java

I have problem to update the result set programmatically. I use VisualAge for Java 3.5 Enterprise Edition. My database is DB2 in AS/400.  I am using JDBC 2.0 API features to update the field in the result set.  I got error message:

SQLException: Cursor state not valid.
SQLState:  24000

Here is my sample code:

import java.sql.*;
import com.ibm.as400.access.*;

class Test {

public static void main(java.lang.String[] args) {
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
       
                // Load Java JDBC driver.
        try {
               
                Class.forName("com.ibm.as400.access.AS400JDBCDriver");
        } catch(java.lang.ClassNotFoundException e) {
                System.err.print("ClassNotFoundException: "+e.getMessage());
                }      
        try {

                con = DriverManager.getConnection("jdbc:as400://wilm620/agtcomp", "myID", "mypassword");
        } catch (SQLException e){
                   System.err.println("Connection Error Exception: "+e.getMessage());
                        }

        try{
                stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
                rs = stmt.executeQuery("select ID from AGTCOMP.TEST");
               
                //move the cursor to the first row and update the ID field (Integer) to 30.
                rs.next();
                rs.updateInt(1,30);
               
                stmt.close();
                con.close();
        }catch (SQLException e){
                System.err.println("SQLException: "+e.getMessage());
                System.err.println("SQLState:  "+e.getSQLState());     
        }

        System.exit(0);
}
}

I have tried to scroll the result set up and down, there is no problem to do that. But I just cannot update it. Of course I can not do rs.updateRow() to update the row in the database either.

Any helps will be highly appreciated.



Weining (Wayne) Xu
Phone: +302.594.2846 
Email:   weining.xu@aig.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.