package com.page.util;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;public class DBManager {
private static Connection connection = null;
static
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","******","******");//自己oracle数据库的帐号密码
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected static Connection getConnection()
{
return connection;
}
public int update(String sql)
{
//boolean flag = false;
int row = 0;
Connection connection = DBManager.getConnection();
PreparedStatement statement = null;
try
{
statement = connection.prepareStatement(sql);
row= statement.executeUpdate();
//
System.out.println(sql);
}
catch (SQLException e)
{
e.printStackTrace();
}
return row;
}
public ResultSet find(String sql)
{
Connection connection = getConnection();
ResultSet result = null;
PreparedStatement statement = null;
try
{
System.out.println(sql);
statement = connection.prepareStatement(sql);
result = statement.executeQuery();
} catch (SQLException e)
{
e.printStackTrace();
}
return result;
}}
3.具体实现分页的代码如下(先看代码后面有注释别太心急慢慢看)
< %@page import="com.sun.crypto.provider.RSACipher"%>
>">
用户信息列表
<!--
http://www.cnblogs.com/xiaoding/archive/2012/07/25/styles.css">
-->
4.好了分页已经完成了,部署好tomcat运行网站吧!(如图)
第二页:
第三页:
第四页:
注意:
总页数的求取是:all_pages=(int)Math.ceil((count_row+page_size-1)/page_size);//计算总页数
sql语句是:String sql="select * from(select rownum rn,p.* from(select * from page )p where rownum<= '"+end_page+"')where rn>'"+start_page+"'";
例如:select *
from
(
select rownum rn,p.*
from
(select *
from page order by id
)p where rownum<= 4
)where rn>3;//要用伪列!!
最后附上我的sql代码:
create table page(
id varchar2(6) not null,
username varchar2(20) not null,
password varchar2(20) not null,
info varchar2(200) default '大家好,很高兴认识你们!',
constraints pk_id primary key(id));select * from page;delete page;drop table page;insert into page (id,username,password) values('000001','黄凯','111111');insert into page (id,username,password,info) values('000002','肖旺','222222','我是JJ,林俊杰!');insert into page (id,username,password) values('000003','申俊杰','qqqq');insert into page (id,username,password,info) values('000004','杨小宇','444444','我班长!');insert into page (id,username,password) values('000005','许世群','xxxxxx');insert into page (id,username,password,info) values('000006','王东宝','666666','我宝爷!');insert into page (id,username,password,info) values('000007','admin','admin','我管理员!');insert into page (id,username,password,info) values('000008','刘鹏','666666','我爱游戏!');insert into page (id,username,password,info) values('000009','刘永军','liu666','我少夜哈哈!');update page set info='我是少爷哈哈!!' where id='000009';select rownum,p.* from page p where rownum between 1 and 4;select count(id) as a from page;select count(id) as count_row from page;select *
from
(
select rownum rn,p.*
from
(select *
from page order by id
)p where rownum<= 4
)where rn>3;select *
from
(
select rownum rn,p.*
from
(select *
from page )p where rownum<= 6
)where rn>3
private static Connection connection = null;
static
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","******","******");//自己oracle数据库的帐号密码
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected static Connection getConnection()
{
return connection;
}
public int update(String sql)
{
//boolean flag = false;
int row = 0;
Connection connection = DBManager.getConnection();
PreparedStatement statement = null;
try
{
statement = connection.prepareStatement(sql);
row= statement.executeUpdate();
//
System.out.println(sql);
}
catch (SQLException e)
{
e.printStackTrace();
}
return row;
}
public ResultSet find(String sql)
{
Connection connection = getConnection();
ResultSet result = null;
PreparedStatement statement = null;
try
{
System.out.println(sql);
statement = connection.prepareStatement(sql);
result = statement.executeQuery();
} catch (SQLException e)
{
e.printStackTrace();
}
return result;
}}
3.具体实现分页的代码如下(先看代码后面有注释别太心急慢慢看)
< %@page import="com.sun.crypto.provider.RSACipher"%>
>">
用户信息列表
<!--
http://www.cnblogs.com/xiaoding/archive/2012/07/25/styles.css">
-->
编号 | 用户帐号 | 用户姓名 | 用户密码 | 用户信息 |
---|---|---|---|---|
1){%>//不在第一页时显示上一页 >">上一页 } if(cur_page %> >">下一页 >">末页//显示最后一页 } %> // 循环显示每一页,本页时不显示超链接(没有下划线) = i %>"> 共页 |
4.好了分页已经完成了,部署好tomcat运行网站吧!(如图)
第二页:
第三页:
第四页:
注意:
总页数的求取是:all_pages=(int)Math.ceil((count_row+page_size-1)/page_size);//计算总页数
sql语句是:String sql="select * from(select rownum rn,p.* from(select * from page )p where rownum<= '"+end_page+"')where rn>'"+start_page+"'";
例如:select *
from
(
select rownum rn,p.*
from
(select *
from page order by id
)p where rownum<= 4
)where rn>3;//要用伪列!!
最后附上我的sql代码:
create table page(
id varchar2(6) not null,
username varchar2(20) not null,
password varchar2(20) not null,
info varchar2(200) default '大家好,很高兴认识你们!',
constraints pk_id primary key(id));select * from page;delete page;drop table page;insert into page (id,username,password) values('000001','黄凯','111111');insert into page (id,username,password,info) values('000002','肖旺','222222','我是JJ,林俊杰!');insert into page (id,username,password) values('000003','申俊杰','qqqq');insert into page (id,username,password,info) values('000004','杨小宇','444444','我班长!');insert into page (id,username,password) values('000005','许世群','xxxxxx');insert into page (id,username,password,info) values('000006','王东宝','666666','我宝爷!');insert into page (id,username,password,info) values('000007','admin','admin','我管理员!');insert into page (id,username,password,info) values('000008','刘鹏','666666','我爱游戏!');insert into page (id,username,password,info) values('000009','刘永军','liu666','我少夜哈哈!');update page set info='我是少爷哈哈!!' where id='000009';select rownum,p.* from page p where rownum between 1 and 4;select count(id) as a from page;select count(id) as count_row from page;select *
from
(
select rownum rn,p.*
from
(select *
from page order by id
)p where rownum<= 4
)where rn>3;select *
from
(
select rownum rn,p.*
from
(select *
from page )p where rownum<= 6
)where rn>3
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27216498/viewspace-739166/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27216498/viewspace-739166/