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();
</