16. Write a java based application to demonstrate the Scrollable Result sets.
Sat Nov 16 2024 00:27:34 GMT+0000 (Coordinated Universal Time)
Saved by
@webtechnologies
import java.sql.*;
public class ScrollableResultSetExample {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/your_database";
String username = "root";
String password = "your_password";
try {
Connection connection = DriverManager.getConnection(url, username, password);
String query = "SELECT * FROM your_table";
Statement statement = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet resultSet = statement.executeQuery(query);
if (resultSet.last()) {
System.out.println(resultSet.getString("column_name"));
}
if (resultSet.first()) {
System.out.println(resultSet.getString("column_name"));
}
resultSet.close();
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
content_copyCOPY
Comments