日期:2014-05-16 浏览次数:20382 次
jsp+oracle实现简单分页
/*1*/
/*==============================================================*/?
/* Table: t_student?????????????????????????????????????????? */?
/*==============================================================*/?
create table t_student? (?
?? s_id????????????? char(10)??????????????????????? not null,?
?? s_name???????????? varchar2(20)??????????????????? not null,?
?? s_age????????????? char(2)???????????????????????? not null,?
?? s_sex????????????? char(2)???????????????????????? not null,?
?? s_class??????????? varchar2(20),?
?? constraint PK_T_STUDENT primary key (s_id)?
);?
?
insert into t_student values('0001','张三','20','男','08级二班') ;?
insert into t_student values('0002','李四','21','女','08级二班') ;?
insert into t_student values('0003','王五','20','男','08级二班') ;?
insert into t_student values('0004','赵柳','20','女','08级一班') ;?
insert into t_student values('0005','杨梅','21','男','08级二班') ;?
insert into t_student values('0006','刘海','23','女','08级一班') ;?
insert into t_student values('0007','孙江','20','女','08级一班') ;?
insert into t_student values('0008','苏灿','22','男','08级二班') ;?
insert into t_student values('0009','王霞','23','女','08级一班') ;?
insert into t_student values('0010','王猛','22','男','08级二班') ;?
insert into t_student values('0011','张相','22','女','08级一班') ;?
insert into t_student values('0012','香橙','20','女','08级一班') ;?
insert into t_student values('0013','李心','21','女','08级二班') ;?
insert into t_student values('0014','张强','20','男','08级一班') ;?
insert into t_student values('0015','赵琳','21','女','08级一班') ;?
insert into t_student values('0016','刘达','21','男','08级二班') ;?
insert into t_student values('0017','苏惠','20','女','08级二班') ;?
insert into t_student values('0018','贾瑞','20','女','08级一班') ;?
insert into t_student values('0019','谷瑞坤','22','男','08级二班') ;?
insert into t_student values('0020','祥还','21','男','08级一班') ;?
commit;
/*2*/
import java.sql.*;?
?
public class DbUtil {?
?
??? private static final String driver = "oracle.jdbc.driver.OracleDriver" ;?
??? private static final String url = "jdbc:oracle:thin:@10.10.10.2:1521:orcl" ;?
??? private static final String username = "test" ;?
??? private static final String password = "test" ;?
??? public static Connection getConnection(){?
??????? Connection conn = null ;?
??????? try{?
??????????? Class.forName(driver) ;?
??????????? conn = DriverManager.getConnection(url, username, password) ;?
??????? }catch(Exception e){?
??????????? e.printStackTrace() ;?
??????? }?
??????? return conn ;?
??? }?
?
??? public static void close(Connection conn) {?
??????? if (conn != null) {?
??????????? try {?
??????????????? conn.close();?
??????????? } catch (SQLException e) {?
??????????????? e.printStackTrace();?
??????????? }?
??????? }?
??? }?
?????
??? public static void close(PreparedStatement pstmt) {?
??????? if (pstmt != null) {?
??????????? try {?
??????????????? pstmt.close();?
??????????? } catch (SQLException e) {?
??????????????? e.printStackTrace();?
??????????? }?
??????? }?
??? }?
?????
??? public static void close(ResultSet rs ) {?
??????? if (rs != null) {?
??????????? try {?
??????????????? rs.close();?
??????????? } catch (SQLException e) {?
??????????????? e.printStackTrace();?
??????????? }?
??????? }?
??? }?
??? public static void main(String[] args) {?
??????? System.out.println(DbUtil.getConnection());?
??? }?
}?
/*3*/
public class Student {?
?
??? private String s_id ;?
??? private String s_name ;?
??? private String s_age ;?
??? private String s_sex ;