另外对Oracle和Java都熟悉的高手帮我看一下这个问题:
http://www.csdn.net/expert/topic/684/684801.xml?temp=.2934229

解决方案 »

  1.   

    int start=pageNo*20;//开始取得数据的行号
    sque="select * from test where rownum>"+start;
    stmVal.setMaxRows(20);
    ResultSet rset1 = stmVal.executeQuery (sque);
    其实纯粹的使用rownum就能控制每次取得的记录数的,但我觉得奇怪的是JDBC API中真的没有取得下20条记录的方法,那又何必有设置结果条数的方法呢!?看来JDBC API这还有不完整的地方,不知道3.0有没有改进!
      

  2.   

    http://go5.163.com/slayers99/arti/notebook/21.htm
    可以参考一下。
      

  3.   

    这是利用rownum来进行记录控制的(供参考)
    如何正确利用Rownum来限制查询所返回的行数? 
    软件环境: 
    1、Windows NT4.0+ORACLE 8.0.4
    2、ORACLE安装路径为:C:\ORANT含义解释: 
    1、rownum是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,
      依此类推,这个伪字段可以用于限制查询返回的总行数。
    2、rownum不能以任何基表的名称作为前缀。 
    使用方法: 
    现有一个商品销售表sale,表结构为:
    month    char(6)      --月份
    sell    number(10,2)   --月销售金额create table sale (month char(6),sell number);
    insert into sale values('200001',1000);
    insert into sale values('200002',1100);
    insert into sale values('200003',1200);
    insert into sale values('200004',1300);
    insert into sale values('200005',1400);
    insert into sale values('200006',1500);
    insert into sale values('200007',1600);
    insert into sale values('200101',1100);
    insert into sale values('200202',1200);
    insert into sale values('200301',1300);
    insert into sale values('200008',1000);
    commit;SQL> select rownum,month,sell from sale where rownum=1;(可以用在限制返回记录条数的地方,保证不出错,如:隐式游标)   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000SQL> select rownum,month,sell from sale where rownum=2;(1以上都查不到记录)没有查到记录SQL> select rownum,month,sell from sale where rownum>5;
    (由于rownum是一个总是从1开始的伪列,Oracle 认为这种条件不成立,查不到记录)
    没有查到记录只返回前3条纪录
    SQL> select rownum,month,sell from sale where rownum<4;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200002      1100
            3 200003      1200
    如何用rownum实现大于、小于逻辑?(返回rownum在4—10之间的数据)(minus操作,速度会受影响)
    SQL> select rownum,month,sell from sale where rownum<10
      2  minus
      3  select rownum,month,sell from sale where rownum<5;   ROWNUM MONTH       SELL
    --------- ------ ---------
            5 200005      1400
            6 200006      1500
            7 200007      1600
            8 200101      1100
            9 200202      1200想按日期排序,并且用rownum标出正确序号(有小到大)
    SQL> select rownum,month,sell from sale order by month;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200002      1100
            3 200003      1200
            4 200004      1300
            5 200005      1400
            6 200006      1500
            7 200007      1600
           11 200008      1000
            8 200101      1100
            9 200202      1200
           10 200301      1300查询到11记录.可以发现,rownum并没有实现我们的意图,系统是按照记录入库时的顺序给记录排的号,rowid也是顺序分配的SQL> select rowid,rownum,month,sell from sale order by rowid;ROWID                 ROWNUM MONTH       SELL
    ------------------ --------- ------ ---------
    000000E4.0000.0002         1 200001      1000
    000000E4.0001.0002         2 200002      1100
    000000E4.0002.0002         3 200003      1200
    000000E4.0003.0002         4 200004      1300
    000000E4.0004.0002         5 200005      1400
    000000E4.0005.0002         6 200006      1500
    000000E4.0006.0002         7 200007      1600
    000000E4.0007.0002         8 200101      1100
    000000E4.0008.0002         9 200202      1200
    000000E4.0009.0002        10 200301      1300
    000000E4.000A.0002        11 200008      1000查询到11记录.正确用法,使用子查询
    SQL> select rownum,month,sell from (select month,sell from sale group by month,sell) where rownum<13;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200002      1100
            3 200003      1200
            4 200004      1300
            5 200005      1400
            6 200006      1500
            7 200007      1600
            8 200008      1000
            9 200101      1100
           10 200202      1200
           11 200301      1300按销售金额排序,并且用rownum标出正确序号(有小到大)
    SQL> select rownum,month,sell from (select sell,month from sale group by sell,month) where rownum<13;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200008      1000
            3 200002      1100
            4 200101      1100
            5 200003      1200
            6 200202      1200
            7 200004      1300
            8 200301      1300
            9 200005      1400
           10 200006      1500
           11 200007      1600查询到11记录.利用以上方法,如在打印报表时,想在查出的数据中自动加上行号,就可以利用rownum。返回第5—9条纪录,按月份排序
    SQL> select * from (select rownum row_id ,month,sell 
      2  from (select month,sell from sale group by month,sell)) 
      3  where row_id between 5 and 9;    ROW_ID MONTH        SELL
    ---------- ------ ----------
             5 200005       1400
             6 200006       1500
             7 200007       1600
             8 200008       1000
             9 200101       1100 
      

  4.   

    这是利用rownum来进行记录控制的(供参考)
    如何正确利用Rownum来限制查询所返回的行数? 
    软件环境: 
    1、Windows NT4.0+ORACLE 8.0.4
    2、ORACLE安装路径为:C:\ORANT含义解释: 
    1、rownum是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,
      依此类推,这个伪字段可以用于限制查询返回的总行数。
    2、rownum不能以任何基表的名称作为前缀。 
    使用方法: 
    现有一个商品销售表sale,表结构为:
    month    char(6)      --月份
    sell    number(10,2)   --月销售金额create table sale (month char(6),sell number);
    insert into sale values('200001',1000);
    insert into sale values('200002',1100);
    insert into sale values('200003',1200);
    insert into sale values('200004',1300);
    insert into sale values('200005',1400);
    insert into sale values('200006',1500);
    insert into sale values('200007',1600);
    insert into sale values('200101',1100);
    insert into sale values('200202',1200);
    insert into sale values('200301',1300);
    insert into sale values('200008',1000);
    commit;SQL> select rownum,month,sell from sale where rownum=1;(可以用在限制返回记录条数的地方,保证不出错,如:隐式游标)   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000SQL> select rownum,month,sell from sale where rownum=2;(1以上都查不到记录)没有查到记录SQL> select rownum,month,sell from sale where rownum>5;
    (由于rownum是一个总是从1开始的伪列,Oracle 认为这种条件不成立,查不到记录)
    没有查到记录只返回前3条纪录
    SQL> select rownum,month,sell from sale where rownum<4;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200002      1100
            3 200003      1200
    如何用rownum实现大于、小于逻辑?(返回rownum在4—10之间的数据)(minus操作,速度会受影响)
    SQL> select rownum,month,sell from sale where rownum<10
      2  minus
      3  select rownum,month,sell from sale where rownum<5;   ROWNUM MONTH       SELL
    --------- ------ ---------
            5 200005      1400
            6 200006      1500
            7 200007      1600
            8 200101      1100
            9 200202      1200想按日期排序,并且用rownum标出正确序号(有小到大)
    SQL> select rownum,month,sell from sale order by month;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200002      1100
            3 200003      1200
            4 200004      1300
            5 200005      1400
            6 200006      1500
            7 200007      1600
           11 200008      1000
            8 200101      1100
            9 200202      1200
           10 200301      1300查询到11记录.可以发现,rownum并没有实现我们的意图,系统是按照记录入库时的顺序给记录排的号,rowid也是顺序分配的SQL> select rowid,rownum,month,sell from sale order by rowid;ROWID                 ROWNUM MONTH       SELL
    ------------------ --------- ------ ---------
    000000E4.0000.0002         1 200001      1000
    000000E4.0001.0002         2 200002      1100
    000000E4.0002.0002         3 200003      1200
    000000E4.0003.0002         4 200004      1300
    000000E4.0004.0002         5 200005      1400
    000000E4.0005.0002         6 200006      1500
    000000E4.0006.0002         7 200007      1600
    000000E4.0007.0002         8 200101      1100
    000000E4.0008.0002         9 200202      1200
    000000E4.0009.0002        10 200301      1300
    000000E4.000A.0002        11 200008      1000查询到11记录.正确用法,使用子查询
    SQL> select rownum,month,sell from (select month,sell from sale group by month,sell) where rownum<13;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200002      1100
            3 200003      1200
            4 200004      1300
            5 200005      1400
            6 200006      1500
            7 200007      1600
            8 200008      1000
            9 200101      1100
           10 200202      1200
           11 200301      1300按销售金额排序,并且用rownum标出正确序号(有小到大)
    SQL> select rownum,month,sell from (select sell,month from sale group by sell,month) where rownum<13;   ROWNUM MONTH       SELL
    --------- ------ ---------
            1 200001      1000
            2 200008      1000
            3 200002      1100
            4 200101      1100
            5 200003      1200
            6 200202      1200
            7 200004      1300
            8 200301      1300
            9 200005      1400
           10 200006      1500
           11 200007      1600查询到11记录.利用以上方法,如在打印报表时,想在查出的数据中自动加上行号,就可以利用rownum。返回第5—9条纪录,按月份排序
    SQL> select * from (select rownum row_id ,month,sell 
      2  from (select month,sell from sale group by month,sell)) 
      3  where row_id between 5 and 9;    ROW_ID MONTH        SELL
    ---------- ------ ----------
             5 200005       1400
             6 200006       1500
             7 200007       1600
             8 200008       1000
             9 200101       1100 
      

  5.   

    我知道用rowid可以,我也作出来了,但是我想用setMaxRows的方式,就像Delphi的ClientDataset一样。
      

  6.   

    老师对你说,好象不可以!这也是我纳闷的地方!不知道JDBC3.0可以了吗?!
      

  7.   

    老实说我还不知道怎么做,这也是我\纳闷的地方,怎么JDBC提供了设置大小的方法却没有取得下一个段记录的方法!也许是JDBC2.0的问题,不知道3.0解决了这个问题没!
      

  8.   

    in your
    http://www.csdn.net/expert/topic/684/684801.xml?temp=.2934229why not use STRUCT?