1. Before running, a MS SQL Server7 database DNS is ready to: Test_db database has a table: guestbook field is: name (varchar), email (varchail), body (text) database user is SA password, you can Modified.
Second, code <% @ page contenttype = "text / html; charset = GB2312"%> <% // variable declaration java.sql.connection sqlcon; // database connection object java.sql.Statement SQLSTMT; // SQL statement object Java.sql.resultSet Sqlrst; // Results The object java.lang.string strcon; // Database connection string java.lang.string strsql; // sql statement int intepagesize; // One page shows the record number INT INTROWCOUNT; // Total INT INTPAGECUNT; / / Total INT INT INTPAGE; // Terminal to page Java.lang.String StrPage; INT i, J, K; // Set a page displayed record number INTPAGESIZE = 5; // Terfer to display page number strpage = request.getParameter ("page"); if (strpage == null) {// indicates that there is no page parameter in querystring, displaying first page data INTPAGE = 1;} else {/// Convert a string to integer = java.lang.integer.Parseint (STRPAGE); if (INTPAGE <1) INTPAGE = 1;} // loads a JDBC-ODBC driver class.Forname ("Sun.jdbc.odbc. JDBCODBCDRIVER "); // Setting the database connection string strCon =" jdbc: odbc: test_db "; // Connect the database SQLCON = java.sql.driverManager.getConnection (StrCon," SA ","); // Create a SQL statement Object SQLSTMT = SQLCON.CREATESTATEMENT (); // Gets the total number of records strsql = "select count (*) from guestbook"; sqlrst = SQLSTMT.ExecuteQuery (strsql); // Execute SQL statement and acquire SQLRST.NEXT (); // When the recording is just opened, the pointer is in the first record before INTRO. wcount = SQLRST.GETINT (1); sqlrst.close (); // Close Result Set // Almented Page Number INTPAGECOUNT = (IntrowCount INTPAGESIZE-1) / INTPAGESIZE; / / Adjust the page number to be displayed (INTPAGE> INTPAGECOUNT) INTPAGE = INTPAGECUNT; / / Settings Get Data SQL Statement Strsql = "SELECT NAME, Email, Body from Guestbook"; // Execute SQL Statement and get the result set SQLRST = SQLSTMT.executeQuery (strsql); // Pointer positioning On the first record of the page to be displayed on i = (INTPAGE-1) * INTPAGESIZE; For (j = 0; j
jdbc-odbc message version p> <