public class MySQLConnection { private String DBDriver="com.mysql.jdbc.Driver"; private String ConnStr="jdbc:mysql://localhost:3306/zb?user=root&password=admin";
public class PageBreak { private String ConnStr=""; private Connection conn=null; private ResultSet rs=null; private int PageSize=0;//一页几个记录 private int PageNumber=0;//页号
public PageBreak() throws java.lang.NullPointerException { MySQLConnection DBConnection=new MySQLConnection(); ConnStr=DBConnection.getConnStr();//得到ConnStr }
public int RecordNumber() throws java.lang.NullPointerException//得到表的记录总数 { rs=null; int ColNumber=0; try{ conn=DriverManager.getConnection(ConnStr); Statement stmt=conn.createStatement(); rs=stmt.executeQuery("select count(*) as ColNumber from User" );
public void setPageSize(int pPageSize)//设置页面大小,并且计算出一共有多少页 { this.PageSize=pPageSize; int RecordNumber=this.RecordNumber(); this.PageNumber=(int)Math.floor(RecordNumber/PageSize); }
public int getPageSize()//得到页面大小 { return this.PageSize; }
public int getPageNumber()//得到页面数 { return this.PageNumber; }
int RecordPerPage=DBConnection.getPageSize();//得到页面大小 int PageNumber=DBConnection.getPageNumber();//得到页面数 int offSet=0;//Select 中的第几页,0开始 int Next=2;//连接“下一页”的初始化 int Pre=1;//连接“上一页”的初始化 int AbsolutePage=1;//绝对页面,1开始。作为连接“下一页”、“上一页”的过渡变量