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());}
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.
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());}