日期:2014-05-16 浏览次数:20460 次
现在加入oracle和sql2005的分页代码实现;
sql2005测试数据脚本:
USE master go IF DB_ID('paginationdb') IS NOT NULL DROP DATABASE paginationdb GO ----建库 CREATE DATABASE paginationdb GO ----建表 USE paginationdb IF EXISTS (SELECT name FROM sysobjects WHERE [name]='student_') DROP TABLE student_ GO ----创建用户信息表 CREATE TABLE student_ ( id_ INT NOT NULL IDENTITY (1,1) PRIMARY KEY, name_ varchar(50), sex_ varchar(50), age_ int, grade_ varchar(50), class_ varchar(50) ) GO --插入测试数据 INSERT INTO student_(name_,sex_,age_,grade_,class_) SELECT 'student1' ,'男', 11 ,'一年级' ,'二班' UNION SELECT 'student2' ,'男', 12 ,'一年级' ,'二班' UNION SELECT 'student3' ,'男', 13 ,'一年级' ,'二班' UNION SELECT 'student4' ,'女', 14 ,'一年级' ,'二班' UNION SELECT 'student5' ,'女', 15 ,'一年级' ,'二班' UNION SELECT 'student6' ,'男', 16 ,'二年级' ,'一班' UNION SELECT 'student7' ,'男', 17 ,'二年级' ,'一班' UNION SELECT 'student8' ,'女', 18 ,'一年级' ,'一班' UNION SELECT 'story1' ,'男', 19 ,'一年级' ,'二班' UNION SELECT 'story2' ,'女', 11 ,'一年级' ,'一班' UNION SELECT 'story3' ,'男', 12 ,'二年级' ,'一班' UNION SELECT 'story4' ,'女', 13 ,'一年级' ,'二班' UNION SELECT 'story5' ,'男', 14 ,'一年级' ,'一班' UNION SELECT 'story6' ,'男', 15 ,'一年级' ,'一班' UNION SELECT 'story7' ,'女', 16 ,'一年级' ,'二班' UNION SELECT 'story8' ,'男', 17 ,'一年级' ,'二班' UNION SELECT 'story9' ,'男', 18 ,'一年级' ,'二班' UNION SELECT 'story8' ,'男', 15 ,'一年级' ,'二班' UNION SELECT 'story8' ,'男', 16 ,'一年级' ,'二班' UNION SELECT 'story10' ,'保密', 16 ,'一年级' ,'二班' GO
oracle测试数据:
//创建学生表 CREATE TABLE STUDENT_ ( ID_ INT PRIMARY KEY, NAME_ VARCHAR2(50), SEX_ VARCHAR2(50), AGE_ INT, GRADE_ VARCHAR2(50), CLASS_ VARCHAR2(50) ) //为学生表创建序列 CREATE SEQUENCE SEQ_STUDENT_ID; //插入测试数据 INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student1','男',11,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student2','男',12,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student3','男',13,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student4','女',14,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student5','女',15,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student6','男',16,'二年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student7','男',17,'二年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'student8','女',18,'一年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story1','男',19,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story2','女',11,'一年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story3','男',12,'二年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story4','女',13,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story5','男',14,'一年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story6','男',15,'一年级','一班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story7','女',16,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story8','男',17,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story9','男',18,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story8','男',15,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story8','男',16,'一年级','二班'); INSERT INTO STUDENT_ VALUES (SEQ_STUDENT_ID.NEXTVAL,'story10','保密',16,'一年级','二班'); COMMIT;
??
?
重构StudentManager类:
package org.forever.manager; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import oracle.jdbc.driver.OracleDriver; import org.forever.entities.Condition; import org.forever.entities.Operation; import org.forever.entities.Order; import org.forever.entities.OrderType; import org.forever.entities.PageInfo; import org.forever.entities.Student; import com.mysql.jd