Pagination problem? Big Brother, help look Jia! ! Thank you! "?

Category: Web Develop
 
md_kingcat
2011-07-13 09:08:09

Sponsored Links
I connect to the database is dynamic, there is a pager, the first page can be displayed properly, they can not view the next page of data, experts who help me look! ! Ah Urgent! ! Prizes? ?
attached: source
<% @ page contentType = "text / html; charset = gb2312"%>
<% @ page import = "java.sql. *, java.io. *"%>
<link href = "index.css" rel = "stylesheet" type = "text / css ">
<%!
String typeToString (int i)
{
String ret =" ";
switch (i)
{
case (1): ret = "CHAR"; break;
case (2): ret = "NUMERIC"; break;
case ( 3): ret = "DECIMAL"; break;
case (4): ret = "INTEGER"; break;
case (5): ret = "SMALLINT"; break;
case (6): ret = "FLOAT"; break;
case (8): ret = "DOUBLE"; break;
case (12): ret = "VARCHAR"; break;
case (91): ret = "DATE"; break;
default: ret = "other";
}
return ret;
}
%>
<%!
String getCol (ResultSet rst, int type, int colNum) throws Exception
{
String ret = "";
switch (type)
{
case (1): ret = rst.getString (colNum); break;
case (4 ): ret = String.valueOf (rst.getInt (colNum)); break;
case (5): ret = String.valueOf (rst.getInt (colNum)); break;
case (6 ): ret = String.valueOf (rst.getFloat (colNum)); break;
case (8): ret = String.valueOf (rst.getDouble (colNum)); break;
case (12 ): ret = rst.getString (colNum); break;
default: ret = "not know";
}
return ret;
}
%>
<%
/ / variable declaration
Connection sqlCon; / / database connection object
Statement sqlStmt; / / SQL statement object
ResultSet sqlRst; / / result set object
java.lang.String strCon = "jdbc: mysql :/ /"; / / database connection string
java.lang.String ip;
java.lang.String strSQL; / / SQL statement
java.lang.String driver;
java.lang.String str;
String username;
String password;

int intPageSize; / / a display Records
int intRowCount; / / Total number of records
int intPageCount; / / total pages
int intPage; / / Subject Showing page
java.lang.String strPage;
int i, j, k; / / set a number of records displayed
intPageSize = 5; / / Get the page number to be displayed

strPage = request.getParameter ("page");
if (strPage == null) {
/ / QueryString that no page in this parameter, then display the first page of data
intPage = 1;
} else {
/ / convert a string to integer
intPage = java.lang.Integer.parseInt (strPage);
if (intPage <1) intPage = 1;}
%>
<%

ip = request.getParameter ("ip");
strCon = strCon + ip + ": 3306 /" + request.getParameter ("mdatabase");
driver = request.getParameter ("mdriver");
str = request.getParameter ("mtablename" ;);
username = request.getParameter ("username");
password = request.getParameter ("password");

session.setAttribute ("strCon" ;, strCon);
session.setAttribute ("driver", driver);
session.setAttribute ("str", str);
session.setAttribute ("username", username);
session.setAttribute ("password", password);

%>

<%
String driver1 = (String) session.getAttribute ("driver");
String strCon1 = (String) session.getAttribute ("strCon");
String str1 = (String) session. getAttribute ("str");
Class.forName (driver1);
/ / set the database connection string
/ / strCon = "jdbc: odbc : bbs ";
/ / connect to database
sqlCon = java.sql.DriverManager.getConnection (strCon1, username, password);
/ / create the SQL statement object
sqlStmt = sqlCon.createStatement ();
/ / System.out.println ("DataBase connected ...");
/ / Set the SQL statement to get data
strSQL = "select count (*) from" + str1;
sqlRst = sqlStmt.executeQuery (strSQL );
/ / execute SQL statements and get the result set
sqlRst.next (); / / record set just opened when the pointer is positioned before the first record
intRowCount = sqlRst.getInt (1);
/ / out.print ("intRowCount:" + intRowCount);
sqlRst.close (); / / close the result set
/ / note count total number of pages
intPageCount = (intRowCount + intPageSize-1) / intPageSize;
/ / out.print ("intPageCount:" + intPageCount);
/ / adjust the page to be displayed if (intPage> intPageCount) intPage = intPageCount;
/ / Set Gets Data SQL statement
strSQL = "select * from" + str1;
System.out.println (strSQL);
/ / execute SQL statements and get results Set
sqlRst = sqlStmt.executeQuery (strSQL);
/ / make records to be displayed in the first
i = (intPage-1) * intPageSize ;
for (j = 0; j <i; j + +)
sqlRst.next ();

ResultSetMetaData meta = sqlRst.getMetaData () ;
int col = meta.getColumnCount ();

%>

<table width = "80%" border = "0" align = "center">
<tr>
<td> <div align = "center"> <strong> You are now visiting the table <% = str1%>, it consisted of <% = col%> field, as follows: </strong> </div> </td>
</tr>
</table>

<table width = "80%" border = "1" align = "center" cellpadding = "0">
<tr>
<% for (int n = 1; n <col +1; n + +)
{
%>
<td height = "36" bgcolor = "# 0066CC"> <div align="center"> <font color="#FFFFFF"> <% = meta.getColumnName (n) %> </font> </div> </td>
<%
}
%>
</tr>
<% i = 0;
while (i <intPageSize&&sqlRst.next()){ %>
; <tr>
<% for (int n = 1; n <col +1; n + +)
{%>
<td height="27"> <div align="center"> <% = sqlRst.getString (n)%> </div> </td>
<%}
%>
</tr>
<%
i + +;
}
%>

<tr bgcolor = "# FFFFFF" align = "center">
<td height = "29" colspan = "7" align = center valign = "top"> <div align="center"> <font color="#0000DD"> first <% = intPage%> page ;
of <% = intPageCount%> page </font>
<% if (intPage> 0) {%>
<a href = "viewdata.jsp? page = <% = 1%>"> <font color="#0000DD"> [First] </font> </a> ;
<%
}
;%>
<% if ((intPage <= intPageCount) && (intPage> 1)) {%>
<a href = "viewdata.jsp? page = <% = intPage-1%> ; "> <font color="#0000DD"> [Previous] </font> </a>
; <%
}
%>
<% if (intPage <intPageCount){%>
<a ; href = "viewdata.jsp? page = <% = intPage +1%>"> <font color="#0000DD"> [Next] </font> </a>
<%
}
;%>
<% if (intPage> 0) {%>
<a href = "viewdata.jsp? page = <% = intPageCount%>"> <font color = " ; # 0000DD "> [end of page] </font>
</a>
<%
}
%>
</div> </td>
</tr>
</table>

<table width="80%" border="0" align="center">
<tr>
<td> <table width = "80%" border = "0" ; align = "right">
<tr>
; <td width="11%" height="43"> <div align="center"> <a href = "index.jsp" ;> <img src="pic/back.gif" width="88" height="23" border="0"> </a> </div> </td>
<td width="11%"> <div align = "center"> <a href="add.jsp"> | Add </a> | | <a href="edit.jsp"> modify </a> | <a href="delete.jsp"> delete </a> | <a href="query.jsp"> query </a> | <a href="javascript:window.history.back();"> Back </a> | </div> </td>
; </tr>
</table> </td>
</tr> ;
</table>
<%
sqlRst.close ();
sqlStmt.close ();
; sqlCon.close ();

%>

</body> ;
</html>

Sponsored Links

momobubian
2011-07-13 09:15:16
see my previous article written in
csdn it
lztie
2011-07-13 09:27:01
hao
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.