TeamJava Forum
[ Read Responses | Post a New Response | Return to the Index ]
[ Previous | Next in Thread | Next ]
Invalid Cursor State
Posted by Nsriram on Saturday, 24 May 2003, at 12:31 p.m.
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
Responses
Post a New Response
The TeamJava Forum is maintained with WebBBS 2.24.