package com.baidu.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.baidu.entity.User;
public class ListDao {
public List getList(int currentPage, int pageSize){
int startRecord = (currentPage-1)*pageSize;
String sql = "select * from tb_cms limit "+startRecord+","+pageSize;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ArrayList<User> list = null;
User user = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/1407JavaJ", "root", "root");
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
list = new ArrayList<User>();
while(rs.next()){
user = new User(rs.getInt(1), rs.getString(2), rs.getString(3));
list.add(user);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
public int getCount(){
String sql = "select count(*) from tb_cms";
int count = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/1407JavaJ", "root", "root");
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
count = rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return count;
}
}
最近下载更多
taoshen95 LV16
2024年12月16日
chengqiang LV13
2022年6月2日
chenzhen23 LV7
2022年4月20日
Reddington LV2
2020年11月4日
hmj792001010 LV12
2020年9月9日
mas_123 LV2
2020年9月7日
ybywx1030 LV7
2020年8月27日
as756390941 LV1
2020年7月14日
hanxinjie LV25
2020年7月13日
调理农务系 LV4
2020年7月2日

最近浏览