Responsible Editor: Entry Time: 2004-10-18 21:20:41 Source: Seventual Channel 1. It is recommended to have a MS SQLSERVER7 database DNS, name: Test_db database: guestbook field is: name (varchar), Email (varchar), the Body (Text) database user is SA cryptographic empty, you can modify it.
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> <