ResultSet deleteRow Example

ResultSet Interface deleteRow example. This example shows you how to use deleteRow method.


ResultSet Interface deleteRow example. void deleteRow() throws SQLException Deletes the current row from this ResultSet object and from the underlying database. This method cannot be called when the cursor is on the insert row.

Here is the code
/*
 * @ # DeleteRow.java
 * A class repersenting use to deleteRow method 
 * of ResultSet in java.sql package
 * version 01 July 2008
 * author Rose India 
 */

import java.sql.*;

public class DeleteRow {

  public static void main(String[] argsthrows Exception {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://192.168.10.59:3306/";
    String db = "Student";

    Class.forName(driver);
    con = DriverManager.getConnection(url + db, "root""root");

    try {
      String sql = "Select * from stu_info";

      st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
          ResultSet.CONCUR_UPDATABLE);
      rs = st.executeQuery(sql);

      rs.last();
      System.out.println(rs.getString(1" " + rs.getString(2));

      rs.deleteRow();

      rs.close();
      st.close();
      con.close();

    catch (Exception e) {
      System.out.println("SQL statement is not executed!");
      System.out.println(e.toString());
    }
  }
}

Output
100 Mahendra
102 Ravi
103 komal
109 Ravi1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US