简体   繁体   中英

Updating ResultSet using another java Class

I am still learning ResultSet and I was trying to update a ResultSet using another class, but then I was prompted an error. The error is

"This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table.".

My statement is working, and it is in ResultSet.CONCUR_UPDATABLE mode. Here's my sample code:

Statement Class:

public abstract class Statements extends mysqlConnect {
     static Statement stmt;
     static ResultSet patient_details;
     String sql=null;

     public void getProfileDetails(String name) throws SQLException{

       stmt = con.createStatement(CONCUR_UPDATABLE, TYPE_SCROLL_SENSITIVE);
       sql="select patient_id, last_name, first_name, middle_name, age, birthdate, gender, height, weight, blood_type, office_location, added_by, picture
            from patient_table
            where concat(last_name, \", \", first_name, \" \", middle_name )
            like '"+name+"%';";
       patient_details = stmt.executeQuery(sql);   }//getProfileDetails

Controller class:

public class Controller extends Statements{

    void setLastName(String ln) throws SQLException{
     patient_details.absolute(patient_details.getRow());
     patient_details.updateString("last_name", ln);
     patient_details.updateRow();
    }//setLastName

}//controller

As per documentation on Connection.createStatement(int, int)

Method signature is:

Statement createStatement( int resultSetType,
                           int resultSetConcurrency ) throws SQLException

Parameters :
resultSetType - a result set type; one of
ResultSet.TYPE_FORWARD_ONLY ,
ResultSet.TYPE_SCROLL_INSENSITIVE , or
ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency - a concurrency type; one of
ResultSet.CONCUR_READ_ONLY or
ResultSet.CONCUR_UPDATABLE

But you have put concurrency type as first parameter.

Change :

stmt = con.createStatement( CONCUR_UPDATABLE, TYPE_SCROLL_SENSITIVE );

To :

stmt = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE,
                            ResultSet.CONCUR_UPDATABLE );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM