package com.pagination.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.pagination.Connection.DBUtils;
import com.pagination.factory.*;
import com.pagination.pojo.Book;
public class BookImpDAO implements BookDAO {
int countPerPage=10;
private static final String TotleCountSQL="select count(*) from book";
private static final String QueryPageSQL="select * from book limit ?,?";
//获取总记录数
public int getTotleCount() {
int totleCount=0;
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn = new DBUtils().getConnection();
ps = conn.prepareStatement(this.TotleCountSQL);
rs = ps.executeQuery();
if(rs.next()){
totleCount = rs.getInt(1);
}
}catch(Exception e){
e.printStackTrace();
}finally{
close(conn, ps, rs);
}
return totleCount;
}
private void close(Connection conn, PreparedStatement ps, ResultSet rs) {
try{
if(rs!=null){
rs.close();
}
}catch(Exception e){
e.printStackTrace();
}
try{
if(ps!=null){
ps.close();
}
}catch(Exception e){
e.printStackTrace();
}
try{
if(conn!=null){
conn.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
//获取总页数
public int getTotlePage() {
int totleCount = this.getTotleCount();
int totlePage = 0;
if(totleCount%countPerPage==0)
totlePage=totleCount/countPerPage;
else
totlePage=totleCount/countPerPage+1;
//totlePage=(totleCount+countPerPage-1)/countPerPage;
return totlePage;
}
//按页获取记录数
public List queryPerPage(int page) {
List<Book> list = new ArrayList<Book>();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
int startRow=(page-1)*countPerPage;
try{
conn = new DBUtils().getConnection();
ps = conn.prepareStatement(this.QueryPageSQL);
ps.setInt(1, startRow);
ps.setInt(2, countPerPage);
rs = ps.executeQuery();
while(rs.next()){
Book book = new Book();
book.setBookname(rs.getString("bookname"));
book.setAuthor(rs.getString("author"));
book.setPublisher(rs.getString("publisher"));
book.setPrice(rs.getDouble("price"));
book.setId(rs.getInt("id"));
list.add(book);
}
}catch(Exception e){
e.printStackTrace();
}finally{
close(conn, ps, rs);
}
return list;
}
//设置每页显示的记录数
public void setCountPerPage(int countPerPage) {
this.countPerPage=countPerPage;
}
public static void main(String[] args){
/* int tolteCount = DAOFactory.getBookImpDAO().getTotleCount();
System.out.println(tolteCount);*/
List list = DAOFactory.getBookImpDAO().queryPerPage(2);
Iterator it = list.iterator();
while(it.hasNext()){
Book book = (Book)it.next();
System.out.println("bookname"+book.getBookname()+"\t"+"publisher"+book.getPublisher()+"\t"+"price"+book.getPrice());
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jsp分页,包括页面刷新和无刷新
共62个文件
class:12个
java:12个
jar:7个
4星 · 超过85%的资源 需积分: 9 122 下载量 64 浏览量
2011-03-14
13:23:41
上传
评论
收藏 2.32MB RAR 举报
温馨提示
数据库用的是MySQL,主要分为刷新页面分页和无刷新页面分页,开发工具是Eclipse
资源推荐
资源详情
资源评论
收起资源包目录
分页.rar (62个子文件)
前台无刷新分页
AjaxPager
.project 1KB
.settings
.jsdtscope 503B
org.eclipse.wst.common.component 457B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
build
classes
WebContent
WEB-INF
web.xml 714B
lib
mysql-connector-java-5.1.0-bin.jar 553KB
page.jsp 2KB
META-INF
MANIFEST.MF 39B
index2.html 452B
js
jquery-1.4.2.js 160KB
index.html 812B
page2.jsp 3KB
.classpath 841B
分页
jsp+mysql分页(forEach)
pagination
.project 1KB
.mymetadata 303B
WebRoot
WEB-INF
web.xml 649B
lib
jstl.jar 21KB
mysql-connector-java-5.1.0-bin.jar 553KB
standard.jar 385KB
classes
com
pagination
dao
BookImpDAO.class 4KB
BookDAO.class 245B
Connection
DBUtils.class 785B
servlet
BooksServlet.class 2KB
factory
DAOFactory.class 444B
pojo
Book.class 1KB
index.jsp 153B
META-INF
MANIFEST.MF 39B
main.jsp 2KB
.myeclipse
src
com
pagination
dao
BookDAO.java 282B
BookImpDAO.java 3KB
Connection
DBUtils.java 344B
servlet
BooksServlet.java 3KB
factory
DAOFactory.java 215B
pojo
Book.java 782B
.classpath 593B
test.sql 2KB
jsp+mysql分页(循环)
pagination
.project 1KB
.mymetadata 303B
WebRoot
WEB-INF
web.xml 649B
lib
jstl.jar 21KB
mysql-connector-java-5.1.0-bin.jar 553KB
standard.jar 385KB
classes
com
pagination
dao
BookImpDAO.class 4KB
BookDAO.class 245B
Connection
DBUtils.class 785B
servlet
BooksServlet.class 2KB
factory
DAOFactory.class 444B
pojo
Book.class 1KB
index.jsp 153B
META-INF
MANIFEST.MF 39B
main.jsp 2KB
.myeclipse
src
com
pagination
dao
BookDAO.java 282B
BookImpDAO.java 3KB
Connection
DBUtils.java 344B
servlet
BooksServlet.java 3KB
factory
DAOFactory.java 215B
pojo
Book.java 782B
.classpath 593B
test.sql 2KB
共 62 条
- 1
zhuciyonghu
- 粉丝: 11
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页