ResultSet afterLast Example

ResultSet class afterLast example. This example shows you how to use afterLast method.


ResultSet class afterLast example. void afterLast() throws SQLException Moves the cursor to the end of this ResultSet object, just after the last row. This method has no effect if the result set contains no rows.

Here is the code
/*
 * @ # AfterLast.java
 * A class repersenting use to AfterLast method 
 * of ResultSet class in java.sql package
 * version 23 June 2008
 * author Rose India 
 */

import java.sql.*;

public class AfterLast {

  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 {
      st = con.createStatement();
      rs = st.executeQuery("select* from stu_info");

      int cursorPosition = rs.getRow();
      rs.absolute(cursorPosition + 1);

      cursorPosition = rs.getRow();
      System.out.println("Moving to position: " + cursorPosition);
      System.out.println("name " + rs.getString(2));

      rs.afterLast();

      cursorPosition = rs.getRow();
      System.out.println("Moving to position: " + cursorPosition);
      System.out.println("name " + rs.getString(2));

    catch (Exception e) {
      System.out.println(e.toString());
    }
  }
}

Output
Moving to position: 1
name Mahendra
Moving to position: 0
java.sql.SQLException: After end of result set

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

HOME | COPYRIGHT | CONTACT US