This commit is contained in:
2026-03-05 15:26:55 +05:30
parent 3835bad178
commit 248e1fdd95
28 changed files with 300 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
package in.test;
import java.sql.*;
public class jdbcscrollresultdemo {
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/jdbc_B2_38";
static final String USERNAME="root";
static final String PASSWORD = "12345";
public static void main(String[] args) {
jdbcscrollresultdemo jdbcscrollresultset = new jdbcscrollresultdemo();
jdbcscrollresultset.getstudentinfo();
}
private void getstudentinfo(){
Connection con = null;
PreparedStatement preparedStatement = null;
try{
Class.forName(JDBC_DRIVER);
con = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
String sql = "select * from student";
preparedStatement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = preparedStatement.executeQuery();
System.out.println("ResultSet move forward");
while (rs.next()) {
int rn = rs.getInt("Rollno");
String name = rs.getString("Name");
System.out.println("Rollno" + rn);
System.out.println("Name" + name);
}
System.out.println("at particular position");
rs.absolute(2);
int id = rs.getInt(1);
String name = rs.getString(2);
System.out.println("Rollno: " + id);
System.out.println("Name: " + name);
rs.close();
}
catch(SQLException se){
se.printStackTrace();
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
finally{
try{
if (preparedStatement!=null) {
preparedStatement.close();
}
}
catch(SQLException sqlException){
sqlException.printStackTrace();
}
try{
if(con!=null){
con.close();
}
}
catch(SQLException sqlException){
sqlException.printStackTrace();
}
}
}
}