JSP database operations routines - Data Paging Display - JDBC 2.0 - Oracle
Abstract: JSP database operations routines - Data Paging Display - JDBC 2.0 - Oracle
<% @ Page contentType = "text / html; 8859_1 charset ="%>
<%
/ / Variable statement
Java.sql.Connection sqlCon; / / Object Database Connection
Java.sql.Statement sqlStmt; / / SQL statements object
Java.sql.ResultSet sqlRst; / / result set targets
Java.lang.String strCon; / / database connection string
Java.lang.String strSQL; / / SQL statement
Int intPageSize; / / records show a few
Int intRowCount; / / Total Records
Int intPageCount; / / total number of pages
Int intPage; / / pages to be displayed
Java.lang.String strPage;
Int i;
/ / Set a few records show
IntPageSize = 2;
/ / Show page in question
StrPage = request.getParameter ( "page");
If (strPage == null) (/ / QueryString that no page in this parameter, the first page of the data shows that at this time
IntPage = 1;
)
Else (/ / string into an integer
IntPage = java.lang.Integer.parseInt (strPage);
If (intPage <1) intPage = 1;
)
/ / Loading JDBC Driver
Java.sql.DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ());
/ / Set up the database connection string
StrCon = "jdbc: oracle: thin: @ linux: 1521: ora4cweb";
/ / Database connections
SqlCon = java.sql.DriverManager.getConnection (strCon, "hzq", "hzq");
/ / Create a rolling can be read-only SQL statement Object
SqlStmt = sqlCon.createStatement (java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
/ / SQL statement prepared
StrSQL = "select name, age from test";
/ / Implementation of SQL statements and access to the results set
SqlRst = sqlStmt.executeQuery (strSQL);
/ / Get the record total
SqlRst.last ();
IntRowCount = sqlRst.getRow ();
/ / Count the total number of pages in mind
IntPageCount = (intRowCount + intPageSize-1) / intPageSize;
/ / Adjust the page to be displayed
If (intPage> intPageCount) intPage = intPageCount;
%>
<head>
</ Head>
<body>
<table Border="1" cellspacing="0" cellpadding="0">
<tr>
<th> Name </ th>
<th> Age </ th>
</ Tr>
<%
If (intPageCount> 0) (
/ / Record pointer positioning to be the first of the page shows that the record
SqlRst.absolute ((intPage-1) * intPageSize + 1);
/ / Display data %> </ Table> No. <% = intPage%> page <= intPageCount%%%> page <if (intPage </ Body> <% / / SQL statement closure targets / / Database closed Tags: java oracle
I = 0;
While (i
<tr>
<td> <= SqlRst.getString% (1 )%></ td>
<td> <% = SqlRst.getString (2 )%></ td>
</ Tr>
<%
SqlRst.next ();
I + +;
)
)
%>
/ / Close the results set
SqlRst.close ();
SqlStmt.close ();
SqlCon.close ();
%>
↑ Back Releated Java Articles
Comments
Leave a Reply






