简体   繁体   中英

Why cant I use more than 1 deleteRow() for many tables in SQL?I found that only the 1st rs's row is deleted, the others arent

String SQL="Select * from APARTMENT_ADDONS";

String SQL2="Select * from APARTMENT_ID";

String SQL3="Select * from APARTMENT_AVAILABLE";

String SQL4="Select * from APARTMENT_COST";

stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

stmt3 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

stmt4 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

rs=stmt.executeQuery(SQL);

rs2=stmt2.executeQuery(SQL2);

rs3=stmt3.executeQuery(SQL3);

rs4=stmt4.executeQuery(SQL4);

rs.deleteRow();

rs2.deleteRow();

rs3.deleteRow();

rs4.deleteRow();

ResultSet.deleteRow() only deletes the current row of the resultset. If you want to delete more than one, run something like:-

String sql = "DELETE FROM MyTable WHERE Whatever = 'Something'";
stmt.executeUpdate(sql);

(Ideally using PreparedStatements of course).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM