
How to move the cursor in scrollable resultset ?

Hi friends,
With the help of this example, you can understands how to move cursor in scrollable Result set.
java.sql.*;
public class ScrollableCursor {
public static void main(String[] args) {
try {
String mysqlDriver = "com.mysql.jdbc.Driver";
Class.forName(mysqlDriver).newInstance();
// Connection String
String connectionString = "jdbc:mysql://192.168.10.13:3306/studentinformation";
String username = "root";
String password = "root";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
con = DriverManager.getConnection(connectionString, username,
password);
// Create scrollable Result Set.
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sqlString = "Select * from s_infor;";
rs = stmt.executeQuery(sqlString);
System.out
.println("---------Student Information(Forword)----------");
while (rs.next()) {
int roll = rs.getInt("s_Roll");
String Name = rs.getString("s_Name");
String Address = rs.getString("s_Address");
System.out.println(roll + " " + Name + " " + Address);
}
System.out
.println("---------Student Information(Previous)----------");
while (rs.previous()) {
int roll = rs.getInt("s_Roll");
String Name = rs.getString("s_Name");
String Address = rs.getString("s_Address");
System.out.println(roll + " " + Name + " " + Address);
}
rs.absolute(1);
System.out
.println("---------Student Information(cursor at specified location)----------");
while (rs.next()) {
int roll = rs.getInt("s_Roll");
String Name = rs.getString("s_Name");
String Address = rs.getString("s_Address");
System.out.println(roll + " " + Name + " " + Address);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.