日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
JSP數(shù)據(jù)分頁實(shí)例:MySQL翻頁

JSP數(shù)據(jù)庫操作可以實(shí)現(xiàn)JSP數(shù)據(jù)分頁。本文提供了一個(gè)MySQL分頁的例子。

一、運(yùn)行前準(zhǔn)備

下載了mysql的jdbc驅(qū)動(dòng)(一個(gè)jar文件)并加載在CLASSPATH。

建一個(gè)MySQL數(shù)據(jù)庫test

數(shù)據(jù)庫中有一個(gè)表:note,字段為:name(varchar)

二、下載,安裝

 
 
 
  1. < %@ page contentType="text/html;charset=gb2312" %> 
  2. < % java.sql.Connection sqlCon; //數(shù)據(jù)庫連接對(duì)象  
  3. java.sql.Statement sqlStmt; //SQL語句對(duì)象  
  4. java.sql.ResultSet sqlRst; //結(jié)果集對(duì)象  
  5. java.lang.String strCon; //數(shù)據(jù)庫連接字符串  
  6. java.lang.String strSQL; //SQL語句  
  7. int intPageSize; //一頁顯示的記錄數(shù)  
  8. int intRowCount; //記錄總數(shù)  
  9. int intPageCount; //總頁數(shù)  
  10. int intPage; //待顯示頁碼  
  11. java.lang.String strPage;  
  12. int i;  
  13. //設(shè)置一頁顯示的記錄數(shù)  
  14. intPageSize = 2;  
  15. //取得待顯示頁碼  
  16. strPage = request.getParameter("page");  
  17. if(strPage==null){  
  18. //表明在QueryString中沒有page這一個(gè)參數(shù),此時(shí)顯示第一頁數(shù)據(jù)  
  19. intPage = 1;  
  20. } else{  
  21. //將字符串轉(zhuǎn)換成整型  
  22. intPage = java.lang.Integer.parseInt(strPage);  
  23. if(intPage< 1) intPage = 1;  
  24. }  
  25. //裝載JDBC驅(qū)動(dòng)程序  
  26. Class.forName("org.gjt.mm.mysql.Driver").newInstance();  
  27. //連接數(shù)據(jù)庫  
  28. sqlCon= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test");  
  29. //創(chuàng)建語句對(duì)象  
  30. sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.  
  31. ResultSet.CONCUR_READ_ONLY); //執(zhí)行SQL語句  
  32. strSQL = "select name from note";  
  33. //執(zhí)行SQL語句并獲取結(jié)果集  
  34. sqlRst = sqlStmt.executeQuery(strSQL);  
  35. //獲取記錄總數(shù)  
  36. sqlRst.last();  
  37. intRowCount = sqlRst.getRow();  
  38. //記算總頁數(shù)  
  39. intPageCount = (intRowCount+intPageSize-1) / intPageSize;  
  40. //調(diào)整待顯示的頁碼  
  41. if(intPage>intPageCount) intPage = intPageCount;  
  42. %> 
  43. < html> 
  44. < head> 
  45. < meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  46. < title>JSP數(shù)據(jù)庫操作例程 - JSP數(shù)據(jù)分頁顯示 - JDBC 2.0 - mysql< /title> 
  47. < /head> 
  48. < body> 
  49. < table border="1" cellspacing="0" cellpadding="0"> 
  50. < tr> 
  51. < th>姓名< /th> 
  52. < /tr> 
  53. < % if(intPageCount>0)  
  54. {  
  55. //將記錄指針定位到待顯示頁的第一條記錄上  
  56. sqlRst.absolute((intPage-1) * intPageSize + 1);  
  57. //顯示數(shù)據(jù)  
  58. i = 0;  
  59. while(i< intPageSize && !sqlRst.isAfterLast()){ %> 
  60. < tr> 
  61. < td> 
  62. < %=sqlRst.getString(1)%> 
  63. < /td> 
  64. < /tr> 
  65. < % sqlRst.next();  
  66. i++;  
  67. }  
  68. }  
  69. %> 
  70. < /table> 
  71. < %=intPage%>頁 共< %=intPageCount%>頁  
  72. < %if(intPage< intPageCount){%>< a href="mysqlpage.jsp?page=< %=intPage+1%>">下一頁< /a>< %}%> 
  73. < %if(intPage>1){%>< a href="mysqlpage.jsp?page=< %=intPage-1%>">上一頁< /a>< %}%> 
  74. < /body> 
  75. < /html> 
  76. < %  
  77. //關(guān)閉結(jié)果集  
  78. sqlRst.close();  
  79. //關(guān)閉SQL語句對(duì)象  
  80. sqlStmt.close();  
  81. //關(guān)閉數(shù)據(jù)庫  
  82. sqlCon.close();  
  83. %> 

如何運(yùn)行JSP數(shù)據(jù)分頁?

將代碼存為文件test.jsp

Orion Application Server下:

Copy到orion的default-web-app目錄下,通過:

 
 
 
  1. http://localhost:port/test.jsp 

訪問測(cè)試

對(duì)于Resin,Tomcat,JWS等等,都可以運(yùn)行通過。JSP數(shù)據(jù)分頁的實(shí)現(xiàn)方法到此介紹完畢。


標(biāo)題名稱:JSP數(shù)據(jù)分頁實(shí)例:MySQL翻頁
當(dāng)前路徑:http://m.5511xx.com/article/djsshhj.html