First, prepare the mysql JDBC driver before running (a JAR file) and load one of the ClassPath (see "Java / JSP learning series (JDK installation)") (If you can't find it, please download from this site) There is a table in a mysql database Test database: Note, field is: Name (varchar) two, download, installation <% @ page contenttype = "text / html; charset = GB2312"%> <% java.sql.connection sqlcon; // Database connection object java.sql.Statement SQLSTMT; // SQL statement object java.sql.resultset Sqlrst; // Result set object java.lang.string strcon; // database connection string java.lang.String strsql; / / SQL statement int intebitSize; // One page displayed record number int intert ost; // record total int INT INT INT INT INT INTPAGE; / / Terminal code Java.lang.String strpage; int i; // A page displayed INTPAGESIZE = 2; // acquire the page number strpage = request.getParameter ("page"); if (strpage == null) {// Indicates that there is no Page in querystring, display First page Data INTPAGE = 1;} ELSE {// Convert cell string to integer = java.lang.integer.parseint (strpage); if (INTPAGE <1) INTPAGE = 1;} // Load JDBC driver Class.Forname ("org.gjt.mm.mysql.driver"). NewInstance (); // Connect database SQLCON = java.sql.driverManager.getConnection ("JDBC: MySQL: // localhost / test"); //// Create a statement object SQLSTMT = Sqlcon.createStatement (java.sql.resultset.type_scroll_insensitive, Java.sql.resultSet.concur_read_only); // Execute SQL statement strsql = "select name from note"; // execute SQL statement and get results set sqlrst = sqlstmt.executeQuery (strsql); // Get record total SQLRST.last ( ); introwcount = sqlrst.getrow (); // Mode total page INTPAGECOUNT = (Introwcount INTPAGESIZE-1) / INTPAGESIZE; / / Adjust the page number IF (INTPAGE> INTPAGECUNT) INTPAGE = INTPAGECUNT;%>
Name tH> tr> <% if (INTPAGECUNT> 0) {// Position the record pointer to the first Sqlrst.absolute (INTPAGE-1) * INTPAGESIZE 1); // Display Data I = 0; While (I <% = SQLRST.GETSTRING (1)%> td> tr> <% sqlrst.next (); i ;}}%> table> No. <% = INTPAGE%> page A total of <% = INTPAGECOUNT%> Page <% IF (INTPAGE |
转载请注明原文地址:https://www.9cbs.com/read-19791.html New Post(0)
|
---|