JSP连接数据库实现分页显示

该博客介绍了如何使用JSP连接数据库实现分页显示。包括创建Users类、定义DAO接口及其实现类,实现查询所有记录和计算总页数的方法。在Servlet中处理请求,传递参数,并跳转到展示页面。最后展示了设计的分页展示界面和web.xml配置。
摘要由CSDN通过智能技术生成

1.新建数据库和表users

2.Users类

public class Users {
private Integer id;
private String uname;
private String pwd;

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}


3.dao:

public interface UsersDao {

public Integer query_counts() throws SQLException;

public List<Users> query_all(int PageNo)throws SQLException;
}


4.daoimpl:

public class UsersDaoImpl implements UsersDao {
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;




public List<Users> query_all(int PageNo) throws SQLException {
List<Users> list = new ArrayList<Users>();
con=new DBUtils().openDB();
String sql="select top 5 * from users where id not in(select top "+(PageNo-1)*5+" id from users order by id asc)order by id asc ";
pstmt=con.prepareStatement(sql);
rs=pstmt.executeQuery();

</

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值