日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

分页显示批量数据

發布時間:2023/12/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 分页显示批量数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

此處一共涉及兩個文件:

  • dbaccess.jsp負責建立數據庫連接,而且靜態包好pase.jsp
  • dbaccess.jsp負責建立連接 1 <%@ page language="java" contentType="text/html; charset=GB2312" 2 pageEncoding="GB2312"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> 7 <title>dbaccess</title> 8 </head> 9 <body> 10 <% 11 try{ 12 Connection con; 13 Statement stmt; 14 Result rs; 15 16 //加載驅動器,線面的代碼是加載MySQL驅動器 17 Class.forName("com.mysql.jdbc.Driver"); 18 //注冊MySQL驅動器、 19 DriverManager.registerDriver(new com.mysql.jdbc.Driver()); 20 21 //用適當的驅動器連接到數據庫 22 String dbUrl = "jdbc:mysql://localhost:3306/DatabaseName?useUnicode=true&charaterEncoding=GB2312"; 23 String dbuser="username"; 24 String dbpwd = "password"; 25 26 //建立connection 27 con = java.sql.driverManager.getConnection(dbUrl,dbuser,dbpwd); 28 //Create sql 29 stmt = con.createStatement(); 30 31 %> 32 33 <%@ include file="pages.jsp" %> 34 35 <% 36 stmt.close(); 37 con.close(); 38 39 }catch(Exception e){ 40 out.println(e.getMessage()); 41 } 42 43 %> 44 </body> 45 </html>

    ?

    ???? 2.pases.jsp負責分頁顯示數據庫中表的數據;

    Pages顯示分頁相關 1 <%@ page language="java" contentType="text/html; charset=GB2312 2 pageEncoding="GB2312%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=GB2312> 7 <title>pages</title> 8 </head> 9 <body> 10 <% 11 //分頁變量的定義; 12 final int e=3; //每頁顯示的記錄數 13 int totalPages=0; //頁面總數 14 int currentPage=1; //當前page編號 15 int totalCount=0; //database中數據的所用數據 16 int p=0//當前pase所顯示的第一條記錄的索引 17 18 //讀取當前待顯示的頁面的編號 19 String tempStr=request.getParameter("CurrentPage"); 20 if (tempStr!=null && !tempStr.equals("")) 21 currentPage=Integer.parseInt(tempStr); 22 23 /*分頁預備*/ 24 25 26 //計算總記錄 27 rs=stmt.executeQuery("select count(*) from datatable;"); 28 if (rs.next()) 29 totalCount=rs.getInt(1); 30 31 //計算總的頁數 32 totalPages=((totalCount%e==0)?(totalCount/e):(totalCount/e+1)); 33 if(totalPages==0) totalPages=1; 34 35 //修正當前page的編號,確保: 1<=currentPage<=totalPages; 36 if(currentPage>totalPages) 37 currentPage=totalPages; 38 else if(currentPag<1) 39 currentPage=1; 40 41 //計算當前page所顯示的第一條記錄索引 42 p=(currentPage-1)*e; 43 44 String sql="select XXX,XXX from datatable order by id limit " +p+",+e"; 45 rs=stmt.executeQuery(sql); 46 %> 47 48 <%-- 顯示page標簽-- %> 49 //yema 50 51 <% 52 for(int i=1;i<=totalPages;i++){ 53 if(i==currentPage) 54 %> 55 <%=i%> 56 57 <% }else{ %> 58 <a href="dbaccess.jsp?curentPage=<%=i%>"><%=i %></a> 59 <% } %> 60 <% } %> 61 62 &nbsp;共<%=totalPages%>頁 ,共<%=totalCount%>條記錄 63 64 65 <table border="1" width=400> 66 67 <tr> 68 <td bgcolor=""> </td> 69 <td bgcolor=""> </td> 70 <td bgcolor=""> </td> 71 <td bgcolor=""> </td> 72 </tr> 73 74 <% 75 while(rs.next()){ 76 String XXX = rs.getString(1); 77 String XXX = rs.getString(2); 78 String XXX = rs.getString(3); 79 float XXX = rs.getfloat(4); 80 81 %> 82 <tr> 83 <td><%=XXX %></td> 84 <td><%=XXX %></td> 85 <td><%=XXX %></td> 86 <td><%=XXX %></td> 87 </tr> 88 89 <% 90 } 91 %> 92 </table> 93 </body> 94 </html>

    ?

    轉載于:https://www.cnblogs.com/wocn/archive/2013/01/10/pages_current.html

    總結

    以上是生活随笔為你收集整理的分页显示批量数据的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。