您好,欢迎访问一九零五行业门户网

java(2014)实现对mysql数据库分页的代码_MySQL

bitscn.com package util;import java.sql.connection;import java.sql.preparedstatement;import java.sql.resultset;import java.sql.sqlexception;import java.util.list;/** * @author hongyu * * @param */public class pagination { // 当前页 private integer nowpage; // 页面要显示信息条数 private integer pagesize; // 根据页面显示的条数计算总页数 private integer countpage; // 根据传入的数据库查询数据库中的信息的条数 private integer total; // 向数据库查询时的开始的下标 private integer startindex; // 向数据库查询时的查询条数 private integer endindex; // 将查询到的数据存放到这里 private list rows; public pagination(integer nowpage, integer pagesize, string tablename) { // 赋值 this.nowpage = nowpage; this.pagesize = pagesize; // 判断当前页是否合法 if (this.nowpage this.countpage) { this.nowpage = this.countpage; } //system.out.println(pagenation中的nowpage========== + this.nowpage); // 计算出开始的记录下标,和每页要显示的条数 if (this.nowpage == 0) { this.startindex = this.nowpage * this.pagesize; this.endindex = this.pagesize; } else { this.startindex = (this.nowpage - 1) * this.pagesize; this.endindex = this.pagesize; } /*system.out.println(this.startindex + ======pagenation中的开始和结束======== + this.endindex+====================总页数+countpage);*/ } // 根据提供的表名向数据库发送请求,计算指定数据表中的数据总条数 public integer getcountsize(string tablename) { int countrecord = 0; string sql = select count(*) as c from + tablename; connection conn = jdbcutil.getconn(); preparedstatement pstmt = null; resultset rs = null; try { pstmt = conn.preparestatement(sql); rs = pstmt.executequery(); if (rs.next()) { countrecord = rs.getint(c); } } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } finally { jdbcutil.release(rs, pstmt); } return countrecord; } public list getrows() { return rows; } public void setrows(list rows) { this.rows = rows; } public integer getstartindex() { return startindex; } public integer getendindex() { return endindex; } public integer gettotal() { return total; } }
bitscn.com
其它类似信息

推荐信息