可滾動結果集

來源:互聯網
上載者:User
     網路文摘"     滾動特性:

  next(),此方法是使遊標向下一條記錄移動。

  previous() ,此方法可以使遊標上一條記錄移動,前提前面還有記錄。

  absolute(int row),可以使用此方法跳到指定的記錄位置。定位成功返回true,不成功返回false,傳回值為false,則遊標不會移動。

  afterLast() ,遊標跳到最後一條記錄之後。

  beforeFirst() ,遊標跳到第一條記錄之前。(跳到遊標初始位)

  first(),遊標指向第一條記錄。

  last(),遊標指向最後一條記錄。

  relative(int rows) ,相對定位方法,參數值可正可負,參數為正,遊標從當前位置向下移動指定值,參數為負,遊標從當前位置向上移動指定值。

  TYPE_FORWARD_ONLY ,該常量指示指標只能向前移動的 ResultSet 對象的類型。 

  TYPE_SCROLL_INSENSITIVE ,該常量指示可滾動但通常不受其他的更改影響的 ResultSet 對象的類型。 

  TYPE_SCROLL_SENSITIVE ,該常量指示可滾動並且通常受其他的更改影響的 ResultSet 對象的類型。
應用:

  1. public ConcurrentLinkedQueue getStockInfoQueue(String table, String stockCode ){   //從資料庫中取出股票資訊,儲存到隊列,並返回隊列
  2.         ConcurrentLinkedQueue<RTmm> clq = new ConcurrentLinkedQueue<RTmm>();
  3.         String sql = "select * from "+table +" where s_code = '" +stockCode+"'";
  4.         String sql2 = "select count(*) from "+table +" where s_code = '" +stockCode+"'";
  5.         try {
  6.             Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);  //可滾動結果集
  7.             ResultSet rs2 = stmt.executeQuery(sql2);
  8.             rs2.last();
  9.             System.out.println("記錄數"+rs2.getInt(1));
  10.             int records = rs2.getInt(1);   //得到記錄個數
  11.             ResultSet rs = stmt.executeQuery(sql);
  12.             if(records < 60){
  13.                 while(rs.next()){
  14.                     String code = rs.getString(1);
  15.                     String time = rs.getString(3);
  16.                     double open = rs.getDouble(4);
  17.                     double close = rs.getDouble(5);
  18.                     double low = rs.getDouble(6);
  19.                     double high = rs.getDouble(7);
  20.                     // RTmm(String code, String dt, double low, double open, double close, double high) 
  21. //                  System.out.println(code+time+open+"  "+close+"  "+high);
  22.                     RTmm rtmm = new  RTmm(code.trim(), time.trim(), low,  open, close, high);
  23.                     clq.add(rtmm);
  24.                 }
  25.             }else{
  26.                 rs.absolute(records - 60);
  27.                 while(rs.next()){
  28.                     String code = rs.getString(1);
  29.                     String time = rs.getString(3);
  30.                     double open = rs.getDouble(4);
  31.                     double close = rs.getDouble(5);
  32.                     double low = rs.getDouble(6);
  33.                     double high = rs.getDouble(7);
  34.                     // RTmm(String code, String dt, double low, double open, double close, double high) 
  35. //                  System.out.println(code+time+open+"  "+close+"  "+high);
  36.                     RTmm rtmm = new  RTmm(code.trim(), time.trim(), low,  open, close, high);
  37.                     clq.add(rtmm);
  38.                 }
  39.             }
  40.         } catch (SQLException  e) {
  41.             e.printStackTrace();
  42.         }
  43.         return clq;
  44.     }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.