Hi. I'm connecting to an Access database via JDBC- ODBC. I can read data and add rows just fine. But I can't delete a row. I"ve tried 2 ways:
#1:
String sql= "select * from data where state=? and school=? and lastname=? and firstname=? ";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection( "jdbc:odbc:profsaccessdata" );
PreparedStatement st = con.prepareStatement(sql);
st.setString(1, state);
st.setString(2, school);
st.setString(3, lastName);
st.setString(4, firstName);
ResultSet rs= st.executeQuery();
while (rs.next())
{
rs.deleteRow();
break ;
}
This gives this error: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid cursor position; no keyset defined
___________
#2 (note the "delete" in the SQL):
String sql= "Delete from data where state=? and school=? and lastname=? and firstname=? ";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection( "jdbc:odbc:profsaccessdata" );
PreparedStatement st = con.prepareStatement(sql);
st.setString(1, state);
st.setString(2, school);
st.setString(3, lastName);
st.setString(4, firstName);
int updated= st.executeUpdate();
System.out.println(updated);
This way, if I give it paramaters I know exist in the database, it will print out "1" in my system.out.println statemnet at the end, which according to the API documentation implies that Row #1 of the resultset was deleted (if I give it bad parameters, it prints out 0, as expected). But the data is still in my Access database.
Any ideas??
Thanks in advance.
Katie