js| Paging
Page is a keyword and cannot be a variable.
conn.jsp
<%
String sdbdriver = \ "Com.ibm.db2.jdbc.app.db2driver\";
String sConnStr = \ "Jdbc:db2:faq\";
Connection conn = null;
Statement stmt = null;
ResultSet Rs=null;
try {
Class.forName (Sdbdriver);
}
catch (Java.lang.ClassNotFoundException e) {
Out.print (\ "FAQ (): \" + e.getmessage ());
}
try{
conn = Drivermanager.getconnection (sconnstr,\ "wsdemo\", \ "wsdemo1\");
stmt = Conn.createstatement ();
}catch (SQLException e) {
Out.print (E.tostring ());
}
%>
query.jsp
<%@ page language=\ "java\" import=\ "java.sql.*\"%>
<%@ page contenttype=\ "text/html; Charset=gb2312\ "%>
<%@ include file=\ "Conn.jsp\"%>
<%
......
int pages=0;
int pagesize=10;
ResultSet result = null;
ResultSet rcount = null;
pages = new Integer (Request.getparameter (\ "Pages\")). Intvalue ();
if (pages>0)
{
String sql=\ "State=\ ' I am not silly \";
int count=0;
try {
Rcount = Stmt.executequery (\ "SELECT COUNT (ID) as ID from user where \" +sql);
catch (SQLException ex) {
Out.print (\ "Aq.executequery: \" + ex.getmessage ());
}
if (Rcount.next ())
Count = Rcount.getint (\ "id\");
Rcount.close ();
if (count>0)
{
Sql=\ "SELECT * from user where \" +SQL;
try {
result = Stmt.executequery (SQL);
}
catch (SQLException ex) {
Out.print (\ "Aq.executequery: \" + ex.getmessage ());
}
int i;
String name;
Result.first ();
Result.absolute ((pages-1) *pagesize);
This method jdbc2.0 support. The compiler passed, but did not know if it was related to the driver, so I had to use the following stupid method.
For (i=1;i<= (pages-1) *pagesize;i++)
Result.next ();
for (i=1;i<=pagesize;i++) {
if (Result.next ()) {
Name=result.getstring (\ "name\");
Out.print (name);
}
Result.close ();
int n= (int) (count/pagesize);
if (N*pagesize<count) n++;
if (n>1)
{for (i=1;i<=n;i++)
Out.print (\ "<a href=query.jsp?pages=\" +i+\ ">\" +i+\ "</a>\");
}
}
}
%>