QueryByPage.java(from 1292.net)(0分)

  • 主题发起人 主题发起人 xiaoboliu
  • 开始时间 开始时间
X

xiaoboliu

Unregistered / Unconfirmed
GUEST, unregistred user!
QueryByPage.java(from 1292.net)
liuxiaobo 2001-09-25
/**
* Title: QueryByPage.java
* Copyright: Copyright (c) 2001
* @author liuxiaobo
* @author xiaoboliu@cmmail.com
* @version 1.1
*/
package justforum.database;
import java.util.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class QueryByPage {
private Connection conn;
private Statement stmt=null;
private ResultSet rs=null;
private String tbl;
private String cnd;
private int rpp;
private HttpServletRequest req;
private int total=0;
private int tpage=1;
private int page=1;
private String urlString;

public void setParam(Connection conn,String tbl,
String cnd, int rpp,HttpServletRequest req,String urlString) {
this.conn=conn;
this.tbl=tbl;
this.cnd=cnd;
this.rpp=rpp;
this.req=req;
this.urlString=urlString;
}
public ResultSet getResultSet() throws SQLException {
if (req.getParameter("page")==null)
page=1;
else

page = Integer.parseInt(req.getParameter("page"));
stmt=conn.createStatement();

// mysql
rs=stmt.executeQuery("SELECT Count(*) FROM "+tbl+" "+cnd );

while (rs.next()) {
total=rs.getInt(1);

}
tpage=(int)Math.ceil((double)total/rpp);

if (total > 0) {
rs=stmt.executeQuery("SELECT * FROM "+tbl+" "+cnd
+" LIMIT "+ (page-1)*rpp + " , " + rpp);

}
//
return rs;

}
public String getNaviBar() {
String str="";

str += "PAGE: "+page+" OF "+tpage;
if(page>1)
str+=" <A href="+urlString+"page="+ 1+">FIRST</A> ";

else

str+="FIRST";
if(page>1)
str+=" <A href="+urlString+"page="+(page-1)+">PREV</A> ";

else

str+="PREV";
if(page <tpage)
str+=" <A href="+urlString+"page="+(page+1)+">NEXT</A> ";

else

str+="NEXT";
if(page <tpage)
str+=" <A href="+urlString+"page="+tpage+">LAST</A> ";

else

str+="LAST";
return str;
}
public void close() throws Exception {
rs.close();
rs=null;
stmt.close();
stmt = null;
}
}
Link:http://www.1292.net
 
好类,好类。
可以只支持mysql
 
接受答案了.
 

Similar threads

I
回复
0
查看
1K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
806
import
I
I
回复
0
查看
2K
import
I
后退
顶部