Class DataList
/ *
* Created on 2004-9-17
*
* To change the template for this generated file go to
* Window> Preferences> Java> Code Generation> Code and Comments
* /
Package com.jia.database;
Import java.sql.connection;
Import java.sql.resultset;
Import java.sql.sqlexception;
Import java.sql.statement;
Import java.util.arraylist;
Import java.util.logging.logger;
/ **
* @Author administrator
*
* To change the template for this generated type comment Go to to TOERATED TYPLATE
* Window> Preferences> Java> Code Generation> Code and Comments
* /
Public class datalist {
Private static string sql_teacher_count = "select count (*) from teacher";
Private static arraylist arr_teacher = new arraylist ();
Private static int totalcount = 0;
/ * Take a total number of records * /
Public static int getteachercount () {
Connection conn = connectdb.connmysqlbyjdbc ();
Statement Stmt = NULL;
Try {
STMT = conn.createstatement ();
ResultSet RS = stmt.executequery (SQL_TEacher_count);
Totalcount = rs.getint (1);
} catch (sqlexception e) {
Logger log = logger.getlogger ("");
Log.severe ("Remove Table Data Error" E.getMessage ());
// Todo: Handle Exception
} finally {
Try {
Stmt.close ();
CONN.CLOSE ();
} catch (exception e) {
}
}
Return TotalCount;
}
/ * Remove the paging record * /
Public static arraylist getteacherlist (int P1, int p2) {
Connection conn = connectdb.connmysqlbyjdbc ();
Statement Stmt = NULL;
Try {
Arr_teacher.clear ();
STMT = conn.createstatement ();
ResultSet RS =
Stmt.executeQuery
"SELECT ID, NAME, Address from Teacher Limit"
P1
","
P2
"" "
While (rs.next ()) {
Teacher teacher = new teacher ();
Teacher.setid (Rs.getstring (1)); Teacher.setName (Rs.getstring (2));
Teacher.Setaddress (Rs.getstring (3));
Arr_teacher.add (teacher);
}
} catch (sqlexception e) {
// Todo: Handle Exception
Logger log = logger.getlogger ("");
Log.severe ("Remove Table Data Error" E.getMessage ());
} finally {
Try {
Stmt.close ();
CONN.CLOSE ();
} catch (exception e) {
}
}
Return arr_teacher;
}
}
Standard Javabean, Teacher Table
/ *
* Created on 2004-9-17
*
* To change the template for this generated file go to
* Window> Preferences> Java> Code Generation> Code and Comments
* /
Package com.jia.database;
/ **
* @Author administrator
*
* To change the template for this generated type comment Go to to TOERATED TYPLATE
* Window> Preferences> Java> Code Generation> Code and Comments
* /
Public class teacher {
Private string name = "";
Private string address = ""
Private string id = ""
/ **
* @Return
* /
Public string getaddress () {
Return Address;
}
/ **
* @Return
* /
Public string getname () {
Return Name;
}
/ **
* @Param String
* /
Public void setaddress (String string) {
Address = String;
}
/ **
* @Param String
* /
Public void setname (String string) {
Name = string;
}
/ **
* @Return
* /
Public string getId () {
Return ID;
}
/ **
* @Param String
* /
Public void setid (String String) {
ID = String;
}
}
Display page default.jsp
<% @ page language = "java" errorpage = "error.html" PageEncoding = "GB2312"%>
<% @ Page Import = "java.util. *"%>
<% @ page import = "com.jia.database.teacher"%>
<% @ page import = "com.jia.database.dataList"%>
head>
<%
Int rownum = datalist.getteachercount ();
INT PAGESIZE = 5;
INT PAGENUM = ROWNUM% PAGESIZE == 0? (ROWNUM / PAGESIZE 1);
INT CURPAGE = 1;
IF (Request.GetParameter ("Curpage")! = null)
CURPAGE = Integer.Parseint (Request.getParameter ("CURPAGE"));
%>
<%
ArrayList Al = Datalist.getteacherList (CURPAGE-1) * Pagesize, Pagesize;
Teacher teacher = new teacher ();
Iterator it = al.listiterator ();
While (it.hasnext ()) {
TEACHER = (teacher) it.next ();
Out.println (Teacher.GetId () Teacher.getName () Teacher.Getaddress () "
");
}
%>
A total of <% = PAGENUM%> page No. <% = CURPAGE%> page
<% IF (CURPAGE-1> 0) {%>
<%}%>
<% IF (CURPAGE 1 <= PAGENUM) {%>
User: password: