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 
  I = 0; 
  While (i 

%>
<tr>
  <td> <= SqlRst.getString% (1 )%></ td> 
  <td> <% = SqlRst.getString (2 )%></ td> 
  </ Tr> 
<%
  SqlRst.next (); 
  I + +; 
  ) 
  ) 
%>

  </ Table> 

  No. <% = intPage%> page <= intPageCount%%%> page <if (intPage    Next <%}%> <% if (intPage> 1 ){%>"> Previous <%}%> 

  </ Body> 

<%
  / / Close the results set 
  SqlRst.close (); 

  / / SQL statement closure targets 
  SqlStmt.close (); 

  / / Database closed 
  SqlCon.close (); 
%>
  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply