Home Tutorial Java Jdbc Jdbcresultset JDBC ResultSet last() Example

 
 

Share on Google+Share on Google+
JDBC ResultSet last() Example
Posted on: October 20, 2010 at 12:00 AM
Advertisement
The ResultSet last() are use to moves the cursor to the last row in the ResultSet object.

JDBC ResultSet last() Example:

The ResultSet last() are use to moves the cursor to the last row in the ResultSet object. It return true if the cursor pointed last row in the ResultSet and return false if the ResultSet object does not contain any row.

Syntax:

ResultSet rs;

Boolean rs.last();

Now we are create a example of ResultSet last().

Example:

package ResultSet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LastMethodExample {

  public static void main(String[] args) {
    
    Connection connection = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "roseindia_jdbc_tutorials";
      String driverName = "com.mysql.jdbc.Driver";
      String userName = "root";
      String password = "root";
      try{
        Class.forName(driverName).newInstance();
        connection = DriverManager.getConnection(url+dbName, userName, password);
        try{
          Statement stmt = connection.createStatement();
          String selectquery = "select user_id, user_name from user";
          ResultSet rs = stmt.executeQuery(selectquery);
          
          rs.last();
          
          System.out.print("User id :" + rs.getInt("user_id"" ");
          System.out.println("User Name :" + rs.getString("user_name"));          
        }
        catch(SQLException s){
          System.out.println(s);
        }
        connection.close();
      }
      catch (Exception e){
        e.printStackTrace();
      }  
  }
}

Now run this example using eclipse IDE and see the output.

Program output:

Database table is:

The eclipse console output is:

Download source code

Advertisement

Related Tags for JDBC ResultSet last() Example :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 20, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com