java_jdbc_可滚动结果集与分页

时间:2021-07-06 06:22:10
	public static void create2(int i) {
Connection conn = null;
Statement st = null;
ResultSet rs = null; try {
conn = JdbcUtils.getConnection();
st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select * from t_user where id<10");
while(rs.next()){
System.out.print(rs.getObject("id")+" ");
System.out.print(rs.getObject("username")+" ");
System.out.print(rs.getObject("password")+" ");
System.out.println();
} System.out.println("----------------------------------");
//定位到哪一条数据开始
rs.absolute(5);
int k=0;
//rs.previous()
while(rs.next()&&k<10){
i++;
System.out.print(rs.getObject("id")+" ");
System.out.print(rs.getObject("username")+" ");
System.out.print(rs.getObject("password")+" ");
System.out.println();
} } catch (SQLException e) {
throw new DaoExcetpion(e.getMessage(), e);
} finally {
JdbcUtils.free(rs, st, conn);
}
}