/**
*
*/
package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
/**
* @author Administrator
*
*/
public class Demo {
/**
* 总共有多少数据
* @return
*/
public int getTotalSize(){
Connection con = DBConnection.getConn();
int i = 0;
try {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select count(*) as length from jobs");
if(rs!=null&&rs.next()){
System.out.println(rs.getInt("length"));
i = rs.getInt("length");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println("i=="+i);
return i;
}
/**
*
* @param size 每页多少
* @param value 第几页
* @return 返回查询第几页数据的列表
* @throws Exception
*/
public List<Bean> page(int size,int value) throws Exception{
List<Bean> list = new ArrayList<Bean>();
Connection con = DBConnection.getConn();
String sql = "select top " + size + " * from jobs where job_id not in (select top " + (value*size) + " job_id from jobs)";
PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while(rs!=null&&rs.next()){
Bean bean = new Bean();
bean.setJob_id(rs.getInt(1));
bean.setJob_desc(rs.getString(2));
bean.setMin_lvl(rs.getString(3));
bean.setMax_lvl(rs.getString(4));
list.add(bean);
}
rs.close();
pst.close();
con.close();
return list;
}
/**
*
* @param args
* @throws Exception
*/
public static void main(String args[])throws Exception{
Demo d= new Demo();
System.out.println("总共的数据"+d.getTotalSize());
}
}
- 1
- 2
- 3
- 4
前往页