您的位置:首页 > 编程语言 > Java开发

java_jdbc_可滚动结果集与分页

2014-01-15 22:55 531 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java