Skip to content

小小前端

明月本无心,行人自回首。

Menu
  • 前端开发
  • 编程技术
  • SQL语句
  • Linux
  • 生活/旅行
  • JSEditor
  • MiniBarCMS
  • About
  • 隐私政策
Menu

Java中实现Mysql分页

Posted on 2016年9月8日2016年9月8日 by king2088

在java开发中,经常使用到分页,下面是java分页的相关代码。


/*
* @author Mr.tao
* create 2016.7.4
*/

package com.bar.page;

import java.sql.*;
import java.util.*;

public class SplitPage
{
//定义结果集对象
private ResultSet rs=null;
private ResultSetMetaData rsmd=null;
//总记录数目
private int rowCount;
//所分的逻辑页数
private int pageCount;
//每页显示的记录数目
private int pageSize;

//初始化,获取数据表中的信息
public void initialize(ResultSet rs,int pageSize)
{
this.pageSize=pageSize;
try
{
this.rs=rs;
this.rsmd=this.rs.getMetaData();
if (this.rs!=null)
{
this.rs.last();
this.rowCount = this.rs.getRow();
this.rs.first();
this.pageCount = (this.rowCount - 1) / this.pageSize + 1;
}
else
{
this.rowCount=0;
}
}
catch(SQLException e)
{
System.out.println(e.toString());
}
}

//将显示结果存到Vector集合类中
public Vector getPage(int ipage)
{
Vector vData=new Vector();
int n=ipage;
int m=0;
m=(n-1)*this.pageSize+1;
try
{
if (this.rs!=null)
{
if (n!=1)
{
this.rs.absolute(m);
}
for(int i=0;i
在JSP中的使用如下:

第<%=showPage%>页/共<%=Page.getPageCount()%>页

首页
<% //判断"上一页"链接是否要显示 if(showPage > 1){
%>
上一页
<% } else out.println("上一页");
//判断"下一页"链接是否要显示
if(showPage < Page.getPageCount()) { %>
下一页
<% } else out.println("下一页");
%>
尾页




1 thought on “Java中实现Mysql分页”

  1. 爱水的鱼说道:
    2016年10月15日 下午12:37

    特别需要,非常感谢博主分享源码!

    回复

发表评论 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

分类

近期文章

  • cordova-plugin-camera在某些android机型中拍照或选择文件时闪退出错的解决办法 2019年10月24日
  • JavaScript nodeJS base64加密解密url参数 2019年10月15日
  • 利用expressJS编写reset api 2019年4月13日
  • angular4 + http拦截器 2019年3月21日
  • ionic navCtrl.pop如何传递参数给上一个页面 2018年11月16日
  • ionic3搭建开发/测试环境 2018年10月25日
  • ionic2、3双击硬件back按键退出应用 2018年10月24日
  • VMware安装Mac OS High Sierra 10.12及高版本无法全屏 2018年8月24日

近期评论

  • 手表资讯发表在《ReactJS环境搭建》
  • king2088发表在《ionic中使用热更新插件cordova-hot-code-push》
  • 重阳节的诗句发表在《常用的sql语句》
  • 新郎致辞发表在《PHP代码实现WordPress相关文章的几种方法》
  • 霸道总裁发表在《vsftpd 提示 unrecognized service 解决办法》

归档

标签

Ajax Android Angular APP Cordova CSS css3 express html5 ionic Java javascript jQuery Linux loading mac Mac OS mongodb MySQL node nodejs PHP react SQL SSH VirtualBox vue vue-cli win10 WordPress WP REST API 主题 兼容性 前端 备份 插件 数据库 数组 服务器 正则表达式 浏览器 热更新 目录 组件 错误
2023年 3月
一 二 三 四 五 六 日
 12345
6789101112
13141516171819
20212223242526
2728293031  
« 10月    
© 2023 小小前端 | Powered by Superbs Personal Blog theme