move resultset cursor to a specific location code example
Example: resultset put cursor to a specific position
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ResultSet_DeletingRow {
public static void main(String args[])throws Exception {
//Registering the Driver
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//Getting the connection
String mysqlUrl = "jdbc:mysql://localhost/mydatabase";
Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");
System.out.println("Connection established......");
//Creating a Statement object
Statement stmt = con.createStatement();
//Query to retrieve the contents of the employee_data table
String query = "select * from cricketers_data";
//Executing the query
ResultSet rs = stmt.executeQuery(query);
//Moving ResultSet object to the required position
rs.absolute(3);
//Contents of the current row
System.out.println("First name: "+rs.getString(1));
System.out.println("Last name: "+rs.getString(2));
System.out.println("Date of birth: "+rs.getDate(3));
System.out.println("Place of birth: "+rs.getString(4));
System.out.println("Country: "+rs.getString(5));
}
}