- package cn.itcast.jdbc;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class ScrollTest {
- /**
- * @param args
- * @throws SQLException
- */
- public static void main(String[] args) throws SQLException {
- scroll();
- }
- static void scroll() throws SQLException {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- try {
- conn = JdbcUtils.getConnection();
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- rs = stmt
- .executeQuery("select id, name, money, birthday from user limit 1, 10");
- while (rs.next()) {
- System.out.println(rs.getObject("id") + "\t"
- + rs.getObject("name") + "\t"
- + rs.getObject("birthday") + "\t"
- + rs.getObject("money"));
- }
- System.out.println("------------");
- rs.absolute(11);
- int i = 0;
- while (rs.previous() && i < 10) {
- i++;
- System.out.println(rs.getObject("id") + "\t"
- + rs.getObject("name") + "\t"
- + rs.getObject("birthday") + "\t"
- + rs.getObject("money"));
- }
- // if (rs.previous())
- // System.out.println(rs.getObject("id") + "\t"
- // + rs.getObject("name") + "\t"
- // + rs.getObject("birthday") + "\t"
- // + rs.getObject("money"));
- } finally {
- JdbcUtils.free(rs, stmt, conn);
- }
- }
- }
运行结果:
1003 dao name2 2011-08-16 200.0
1004 daoname1 2011-08-16 200.0
1005 daoname1 2011-08-16 200.0
1006 daoname1 2011-08-16 200.0
1007 daoname1 2011-08-16 200.0
1008 daoname1 2011-08-16 8800.1
1009 daoname1 2011-08-16 200.0
1010 daoname1 2011-08-16 200.0
1012 daoname1 2011-08-16 200.0
1015 name4 2011-09-11 200.0
------------
1015 name4 2011-09-11 200.0
1012 daoname1 2011-08-16 200.0
1010 daoname1 2011-08-16 200.0
1009 daoname1 2011-08-16 200.0
1008 daoname1 2011-08-16 8800.1
1007 daoname1 2011-08-16 200.0
1006 daoname1 2011-08-16 200.0
1005 daoname1 2011-08-16 200.0
1004 daoname1 2011-08-16 200.0
1003 dao name2 2011-08-16 200.0
阅读(725) | 评论(0) | 转发(0) |