程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> myeclipse_sqlsever-sqlsever_myeclipse分頁問題

myeclipse_sqlsever-sqlsever_myeclipse分頁問題

編輯:編程解疑
sqlsever_myeclipse分頁問題
List<Book> list = new ArrayList<Book>();
Connection con = DBConnection.getCon();
//String sql = "select top ? * from bookInformation where id not in (select top ? id from bookInformation)";
//String sql = "select top 9 *  from bookInformation "; 
String sql = "select top + Book.PAGE_SIZE  from bookInformation where id not in (select top  (page-1)*Book.PAGE_SIZE  id from bookInformation)";

try{
    PreparedStatement stmt = con.prepareStatement(sql);                 
    stmt.setInt(1,Book.PAGE_SIZE);     //設置查詢數據所返回的記錄數
    stmt.setInt(2,(page-1)*Book.PAGE_SIZE);   //設置查詢記錄的開始位置


    ResultSet rst  = stmt.executeQuery();

上面是代碼,出現了索引超出范圍的錯誤。請大家幫我解決一下?非常感謝

最佳回答:


 String sql = "select top + Book.PAGE_SIZE  from bookInformation where id not in (select top  (page-1)*Book.PAGE_SIZE  id from bookInformation)";

->
String sql = "select top " + Book.PAGE_SIZE + "  from bookInformation where id not in (select top " + (page-1)*Book.PAGE_SIZE + " id from bookInformation)";

stmt.setInt(1,Book.PAGE_SIZE);     //設置查詢數據所返回的記錄數
stmt.setInt(2,(page-1)*Book.PAGE_SIZE);   //設置查詢記錄的開始位置
刪除

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved