• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

mysql 搞代码 4年前 (2022-01-09) 18次浏览 已收录 0个评论

gaodaima.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;	// 根据页面显示的条数计算总页数	<b>本文来源gao@dai!ma.com搞$代^码!网7</b>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;	}	}

gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:java(2014)实现对mysql数据库分页的代码_MySQL
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址