java分页语句怎么写

1.JAVA中的分页程序怎样编写转一个jsp分页<%@ page contentType="text/html;charset=8859_1" %><%//变量声明java.sql.Connection sqlCon; //数据库连接对象java.sql.Statement sqlStmt; //SQL语句对象java.sql.ResultSet sqlRst; //结果集对象java.lang.String strCon; //数据库连接字符串java.lang.String strSQL; //SQL语句int intPageSize; //一页显示的记录数int intRowCount; //记录总数int intPageCount; //总页数int intPage; //待显示页码java.lang.String strPage;int i;//设置一页显示的记录数intPageSize = 2;//取得待显示页码strPage = request.getParameter("page");if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据intPage = 1;}else{//将字符串转换成整型intPage = java.lang.Integer.parseInt(strPage);if(intPage<1) intPage = 1;}//装载JDBC驱动程序java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());//设置数据库连接字符串strCon = "jdbc:oracle:thin:@linux:1521:ora4cweb";//连接数据库sqlCon = java.sql.DriverManager.getConnection(strCon,"hzq","hzq");//创建一个可以滚动的只读的SQL语句对象sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);//准备SQL语句strSQL = "select name,age from test";//执行SQL语句并获取结果集sqlRst = sqlStmt.executeQuery(strSQL);//获取记录总数sqlRst.last();intRowCount = sqlRst.getRow();//记算总页数intPageCount = (intRowCount+intPageSize-1) / intPageSize;//调整待显示的页码if(intPage>intPageCount) intPage = intPageCount;%><meta ; charset=gb2312">JSP数据库操作例程 - 数据分页显示 - JDBC 2.0 - Oracle<body>姓名年龄<%if(intPageCount>0){//将记录指针定位到待显示页的第一条记录上sqlRst.absolute((intPage-1) * intPageSize + 1);//显示数据i = 0;while(i<%=sqlRst.getString(1)%><%=sqlRst.getString(2)%><%sqlRst.next();i++;}}%>第<%=intPage%& gt;页 共<%=intPageCount%>页 <%if(intPage">下一页& lt;%}%> <%if(intPage>1){%>">上一页& lt;%}%><%//关闭结果集sqlRst.close();//关闭SQL语句对象sqlStmt.close();//关闭数据库sqlCon.close();%> 。
2.用JAVA怎么写分页代码totalPages) pageNo = totalPages;
int startPos = (pageNo - 1 ) * pageSize;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0 order by pdate desc limit " + startPos + ", " + pageSize);
%>
ttps://wenwen.sogou.com/login/redirect?url=4%2Floose.dtd%22%3E" >4/loose.dtd">
微型BBS
3.java分页写法import java.sql.*;
public class javaBeanBO {
private ResultSet rs=null;
private Connection ct=null;
private PreparedStatement ps=null;
/**
*
* @param pageSize
* @return
*/
public int getPageCount(int pageSize){ //int pageSize每页显示多少条信息
int pageCount=0;//共有多少页
int rowCount=0;//共有多少条信息
try {
//连接数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=movie","sa","111111");//movie是数据库,sa是账号,111111是密码
//查询数据库
ps=ct.prepareStatement("select count(*) from message");//message是查询的表
rs=ps.executeQuery();
while(rs.next()){
//得到共有多少条信息数
rowCount=rs.getInt(1);
}
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
【java分页语句怎么写】}else{
pageCount=rowCount/pageSize+1;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.close();
}
//返回共有多少页
return pageCount;