解决方案
以下示例使用 ResultSet 的 first、last、deletRow、getRow、insertRow 方法删除或插入 Row 并将 ResultSet 的指针移动到第一条或最后一条记录。
import java.sql.*;
public class jdbcConn {
public static void main(String[] args) throws Exception {
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection(
"jdbc:derby://localhost:1527/testDb","name","pass");
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String query = "select * from emp";
ResultSet rs = stmt.executeQuery(query);
rs.last();
System.out.println("No of rows in table = "+rs.getRow());
rs.moveToInsertRow();
rs.updateInt("id", 9);
rs.updateString("name","sujay");
rs.updateString("job", "trainee");
rs.insertRow();
System.out.println("Row added");
rs.first();
rs.deleteRow();
System.out.println("first row deleted");
}
}