bean文件:
package bean;
import java.sql.*;
import java.util.Vector;
public class Conn {
public int resultPage;//用于取得最后是第几页的内容,因为给的要显示的页可能大于所有的页数,这时就要调整.
public int totalPage;
public Connection getConn()
{
Connection C=null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
C= DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=admin&useUnicode=true&characterEncoding=8859_1");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return C;
}
public void doDel(int ID)
{
Connection con=getConn();
try {
Statement st=con.createStatement();
st.execute("delete from test where id="+ID);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Vector getResult(int pageSize,int currentPage,String sql)
{
int rowNum=0;
int page=0;
int beginRow=0;
Vector resultRows=new Vector();
try{
Statement st=getConn().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=st.executeQuery(sql);
rs.last();
rowNum=rs.getRow();
if(rowNum%pageSize==0)
{
page=rowNum/pageSize;
}
else
page=rowNum/pageSize+1;
if(currentPage>page)
{
currentPage=page;
}
if(currentPage<1)
{
currentPage=1;
}
resultPage=currentPage;
totalPage=page;
beginRow=(currentPage-1)*pageSize+1;
//System.out.println("beginRow:"+beginRow);
rs.absolute(beginRow);
int i=1;
while(!rs.isAfterLast() && i<=pageSize)
{
Vector v=new Vector();
v.add(rs.getInt(1));
v.add(rs.getString(2));
v.add(rs.getInt(3));
resultRows.add(v);
i++;
rs.next();
}
[1] [2] 下一页