The Artima Developer Community
Sponsored Link

Java Answers Forum
Invalid Cursor State

1 reply on 1 page. Most recent reply: Jun 23, 2003 11:55 PM by devendra

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
NSriram

Posts: 4
Nickname: nan
Registered: May, 2003

Invalid Cursor State Posted: May 24, 2003 9:27 AM
Reply to this message Reply
Advertisement
Hello,
I am pasting a portion of a code here. This attempts to find a record from the database using the name that we give in the textfield, and delete it if not needed.
'i' is an instance of the InfoPanel class that has all the labels and text fields (for name, sub, marks and grd).
.......
.......
try {
if (evt.getSource() == find) { // outer if block

if ( !i.name.getText().equals("")) { // inner if block

Statement st = con.createStatement();
String query = "Select name, sub, marks, grade from SCORE where NAME = '" + i.name.getText() + "'";
ResultSet rs = st.executeQuery(query);
display(rs);
rs.close();
st.close();
} //end inner if
else
System.out.println("Enter a name and then click on Find");
}//end outer if

if (evt.getSource() == del) {
Statement st = con.createStatement();
String query = "Delete from SCORE where NAME = '" + i.name.getText() + "'";
st.executeUpdate(query);
st.close();
System.out.println("Record Deleted");

}
} //end try block

catch (SQLException sq) { System.out.println("No matching record found to delete");}
catch (Exception e) {System.out.println(e.getMessage());}

}


public void display(ResultSet rs) {
try {

rs.next();
i.sub.setText(rs.getString(2));
i.marks.setText(String.valueOf(rs .getInt(3)));
i.grd.setText(rs.getString(4));

}
catch (SQLException sql)
{System.out.println("No matching record found ..."+" "+ sql.getMessage());}

catch (Exception e) {System.out.println(e.getMessage());}
}

......
......

I get [Microsoft][ODBC Driver Manager]Invalid Cursor State error (in the "display" method block)when I try to run the program. Also the records aren't deleted when I try to delete them. It says "Record Deleted" but it isn't.
I am using Oracle as my backend.

Note: An almost similar program works fine with MSAccess.

Thanks
NS


devendra

Posts: 3
Nickname: dev257
Registered: Jun, 2003

Re: Invalid Cursor State Posted: Jun 23, 2003 11:55 PM
Reply to this message Reply
the select query in your case isn't returning a resulset just try n make ur "display" method as given below and it will not give an error(after proper error handling)

public void display(ResultSet rs) {
try {

if(rs.next()) {
i.sub.setText(rs.getString(2));
i.marks.setText(String.valueOf(rs .getInt(3)));
i.grd.setText(rs.getString(4));
}
}
catch (SQLException sql)
{System.out.println("No matching record found ..."+" "+ sql.getMessage());}

catch (Exception e) {System.out.println(e.getMessage());}
}

Flat View: This topic has 1 reply on 1 page
Topic: threads Previous Topic   Next Topic Topic: Course Of Action

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use