java_jdbc_スクロール可能な結果セットとページング
1183 ワード
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);
}
}