[Java] JDBC 07 处理可滚动的结果集

import java.sql.*;

public class TestScroll {
    public static void main(String args[]) {
    // 是否 支持可滚动的结果集,要依赖于数据库厂商给我们提供的 JDBC 的开发包
        try {
            new com.mysql.jdbc.Driver();
            
            String url = "jdbc:mysql://localhost/mydata?user=root&password=root";
            
            Connection conn = DriverManager.getConnection(url);
            
            Statement stmt = conn.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = stmt
                    .executeQuery("select * from dept2");
            rs.next();
            System.out.println(rs.getInt(1));
            rs.last();
            System.out.println(rs.getString(1));
            System.out.println(rs.isLast());
            System.out.println(rs.isAfterLast());
            System.out.println(rs.getRow());
            rs.previous();
            System.out.println(rs.getString(1));
            rs.absolute(6);
            System.out.println(rs.getString(1));
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
    }
}

Output:

 61

98
true
false
6
77
98
原文地址:https://www.cnblogs.com/robbychan/p/3786574.html