In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "MySQL database JSP paging query display code", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "MySQL database JSP paging query display code"!
MySQL is no stranger to JSP learners, so how to implement the JSP paging query module? let's get started!
This function creates a total of two JavaBean components and a JSP page to display the paging page, * is to deal with the database connection to the JavaBean,*** JavaBean is to handle the JSP paging query results code, the third JSP is to call the second JavaBean, display the results of the JSP paging query!
◆ the following is the code for a JavaBean that connects to the MYSQL database:
Package data
Import java.sql.*
Public class LoginData {
Connection conn=null
Public LoginData () {
This.connect ()
}
Public Connection getConn () {
Return this.conn
}
Public boolean connect () {
Try {
/ / create a database connection using the JDBC bridge
Class.forName (org.gjt.mm.MYSQL.Driver) .newInstance ()
/ / use the getConnection () method of the DriverManager class to establish a connection
/ / * parameters define the user name, and the second parameter defines the password
This.conn=java.sql.DriverManager.getConnection ("
Jdbc:MYSQL://localhost:3306/logindemo?useUnicode=true&characterEncoding=gb2312 "
"root", "123456")
} catch (Exception ex) {
Ex.printStackTrace ()
Return false
}
Return true
}
}
◆ below is a JavaBean code that handles the JSP paging query display of the MySQL database
Package data; import java.sql.*; import java.util.*; public class strongSplitPage {private Connection conn=null; private Statement stmt=null; private ResultSet rs=null; private ResultSetMetaData rsmd=null; / / sql query statement private String sqlStr; / / Total number of records private int rowCount; / / logical pages divided private int pageCount; / / number of records displayed per page private int pageSize / / define the number of columns in the table private int columnCount; private int irows; public void initialize (String sqlStr,int pageSize,int showPage) {this.sqlStr=sqlStr; this.irows=pageSize* (showPage-1); this.pageSize=pageSize; try {LoginData loginData=new data.LoginData (); this.conn=loginData.getConn (); thisthis.stmt=this.conn.createStatement () Thisthis.rs=this.stmt.executeQuery (this.sqlStr); thisthis.rsmd=this.rs.getMetaData (); if (this.rsroomnull) {this.rs.last (); thisthis.rowCount=this.rs.getRow (); this.rs.first (); thisthis.columnCount=this.rsmd.getColumnCount (); this.pageCount= (this.rowCount-1) / this.pageSize+1 This.rs.close (); this.stmt.close ();} thisthis.sqlStr=this.sqlStr+ "limit" + this.irows+ "," + this.pageSize; thisthis.stmt=this.conn.createStatement (); thisthis.rs=this.stmt.executeQuery (this.sqlStr);} catch (Exception ex) {ex.printStackTrace () }} public Vector getPage () {Vector vData=new Vector (); try {if (this.rsroomnull null) {while (this.rs.next ()) {String [] sData=new String [this.columnCount]; for (int jumb0bot j < this.columnCount) VData.addElement (sData);} this.rs.close (); this.stmt.close (); this.conn.close ();}} catch (Exception ex) {ex.printStackTrace () } return vData;} / / get the total number of pages public int getPageCount () {return this.pageCount;} / / get the total number of records in the data table public int getRowCount () {return this.rowCount;}}
Below the ◆ is the display of the JSP paging query page
<% @ page contentType= "text/html Charset=gb2312 "language=" java "import=" java.sql.* "errorPage="% > <% @ page import= "java.io.*"% > <% @ page import= "java.util.*"% > <% @ page import= "data.*"% > < jsp:useBean id= "pages" scope= "page" class= "data.strongSplitPage" / > <%! / / displays the number of records per page int pageSize=10 String sqlStr= "; / / current page int showPage=1;% > <% sqlStr=" select * from userinfo order by id "; String strPage=null; / / get the page strPage=request.getParameter to jump to (" showPage "); if (strPage==null) {showPage=1; pages.initialize (sqlStr,pageSize,showPage);} else {try {showPage=Integer.parseInt (strPage) Pages.initialize (sqlStr,pageSize,showPage);} catch (NumberFormatException ex) {showPage=1; pages.initialize (sqlStr,pageSize,showPage);} if (showPage < 1) {showPage=1; pages.initialize (sqlStr,pageSize,showPage);} if (showPage > pages.getPageCount ()) {showPage=pages.getPageCount (); pages.initialize (sqlStr,pageSize,showPage) }} / / get the data collection to display Vector vData=pages.getPage ();% > < html xmlns= "http://www.w3.org/1999/xhtml" > < head > < meta http-equiv=" Content-Type "content=" text/html Charset=gb2312 "/ > < title > pagination shows < / title > < / head > < body bgcolor=" # ffffff "text=" # 000000 "> < H2 align=center > personal basic Information < / H2 > < div align=center > < table border=" 1 "cellspacing=" 0 "cellpadding=" 0 "width=" 80% > < tr > < th width= "20%" > number < / th > < th width= "40%" > Student ID < / th > < th width= "40%" > name < / th > < / tr > <% for (int item0) I < vData.size ()) {/ / display the number of data String [] sData= (String []) vData.get (I) < tr > < td > <% = sData [0]% > < / td > < td > <% = sData [1]% > < / td > < td > <% = sData [2]% > < / td > < / tr > <%} > < / table > < p > < form action= "word_list_javabean.jsp" method= "get" target= "_ self" > < p > < font color=red > <% = pages.getRowCount ()% > < / font > <% = pageSize% > < font color=red > <% = showPage% > < / font > page / total < font color=red > <% = pages.getPageCount ()% > < / font > page [< a href= "word_list_javabean.jsp?showPage=1" target= "_ self" > homepage < / A >] <% / / determine whether the previous page link should display if (showPage > 1) {% > [< a href= "word_list_javabean.jsp?showPage= <% = showPage-1% >" target= "_ self" > previous page < / a >] <%} else {% > [previous page] <%} / / determine whether the next page link displays if (showPage < pages.getPageCount ()) {% > [< a href= "word_list_javabean.jsp?showPage= <% = showPage+1% >" target= "_ self" > next page < / a >] <%} else { % > [next page] <%}% > [< a href= "word_list_javabean.jsp?showPage= <% = pages.getPageCount ()% >" target= "_ self" > last page < / a >] go to < select name= "select" > <% for (int xanth1) X < = pages.getPageCount (); out.println +) {% > < option value= "<% = x% >" <% if (showPage==x) {out.println ("selected") }% > <% = x% > < / option > <%}% > < / select > page < input type= "submit" name= "go" value= "submit" / > < / p > < / form > < / p > < / div > < / body > < / html > Thank you for your reading The above is the content of "the code displayed by the JSP paging query of the MySQL database". After the study of this article, I believe you have a deeper understanding of the code displayed by the JSP paging query of the MySQL database, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.