-Data pagination Display-JDBC 2.0:ODBC
Through the JDBC:ODBC can realize the JSP to the database operation, in this example I wrote the connection of the database in a JavaBean, can realize to reuse
pagetest.jsp file:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<% @page contenttype= "text/html;charset=gb2312"%>
<jsp:usebean id= "Htool" scope= "session" class= "Zbean". Htmltool "/>
<jsp:usebean id= "Jodb" scope= "session" class= "Zbean". Jodb "/>
<title> Database Paging Test </title>
<%
Defining the ResultSet Class
Java.sql.ResultSet rst;
Set ODBC data source
Jodb.setconnstr ("Jdbc:odbc:jtest", "", "");
Set JDBC Driver
Jodb.setdbdriver ("Sun.jdbc.odbc.JdbcOdbcDriver");
Executes the SQL statement, calling the Jodb class's Execute method
Rst=jodb.execute ("SELECT * from Gbook");
%>
<%
int startrownum;
int pagesize=10;
Rst.last ();
int Rowcount=rst.getrow ();
int pagecount= (rowcount+pagesize-1)/pagesize;
int intpage;
String strpage=request.getparameter ("page");
if (strpage==null)
{
intpage=1;
}
Else
{
Intpage=java.lang.integer.parseint (strpage);
if (intpage<1) intpage=1;
if (Intpage>pagecount) Intpage=pagecount;
}
Startrownum= (intPage-1) *pagesize+1;
%>
<body>
public class Jodb
{
Public String sdbdriver= "Sun.jdbc.odbc.JdbcOdbcDriver";
Public String sConnStr;
public long Count;
String uid;
String pwd;
Connection Conn=null;
ResultSet Rs=null;
Public string[] Split (String str,string Strin)
{
Char[] Temp_array;
Temp_array=str.tochararray ();
int Strlength=str.length ();
int Strinlength=strin.length ();
int strintimes=0;
int strindex[]=new Int[strlength];
int i=0;
int ii=0;
while (I<=strlength-strinlength)
{
String temp_str= "";
for (int j=i;j<i+strinlength;j++)
{
TEMP_STR=TEMP_STR+TEMP_ARRAY[J];
}
if (Temp_str.equals (Strin))
{
strintimes++;
Strindex[ii]=i;
I=i+strinlength;
ii++;
}
Else
{
i++;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.