Click here to Skip to main content
15,907,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me I have exception (invalid cursor state) what should I do ??
public void billnumber(){
       try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection cn = DriverManager.getConnection("Jdbc:Odbc:ds_comboPractice");
    Statement stmt = cn.createStatement();
    rs = stmt.executeQuery("select max(Bill_Number) from combopractice");
    int a = rs.getInt(1);
    txt4.setText(String.valueOf(a));
        }
        catch (Exception ex){JOptionPane.showMessageDialog(this, ex.getMessage());
        
        }
    }
Posted
Updated 23-Dec-13 7:57am
v2
Comments
Sergey Alexandrovich Kryukov 23-Dec-13 14:02pm    
In what line?
—SA
Member 10484162 23-Dec-13 14:26pm    
after run this program. I got this error, champion please help me.
Sergey Alexandrovich Kryukov 23-Dec-13 15:48pm    
You need to run it under the debugger and provide comprehensive exception information information, importantly, the line in code.
I am not familiar with the Java SQL binding you are using, but the one who is would need a good issue report from you. But you can just read the documentation.
—SA

Have you created the database correctly? also, you have to put username and password to the url. Here is a solution http://stackoverflow.com/questions/17663167/jdbc-driver-connection-problems-sun-jdbc-odbc-jdbcodbcdriver[^]
 
Share this answer
 
Problem is here :
Java
int a = rs.getInt(1);

It should be like :

Java
while(rs.next()){
   int a = rs.getInt(1);
}


After getting the resultSet, you have to move the result set pointer(cursor) to the first row to point the first record.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900