JSP怎样利用List实现分页?
将从数据库中提取的内容保存在一个List里面!然后怎样List里面得内容怎样用分页的形式显示出来!...
将从数据库中提取的内容保存在一个List里面!然后怎样List里面得内容怎样用分页的形式显示出来!
展开
2013-10-27
展开全部
/****给入参数 当前页 和每页显示的记录数 可以返回 想要的集合***/
public Collection getBooks(int page, int n) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int sumRs;
int sumPage;
int currRs;
ArrayList<Bean> booklist = new ArrayList<Bean>();
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("select * from 你的表");
rs.last();
sumRs = rs.getRow();
sumPage = (sumRs % n) == 0 ? (sumRs / n) : (sumRs / n + 1);
currRs = (page - 1) * n + 1;
rs.absolute(currRs);
for (int i = 1; i <= n; i++) {
Bean book = new Bean(rs.getInt(1), rs.getString(2), rs
.getString(3), rs.getString(4), rs.getString(5), rs
.getFloat(6), rs.getInt(7), rs.getString(8), rs
.getString(9));
booklist.add(book);
rs.next();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeResultSet(rs);
closeStatement(stmt);
closeConnection(conn);
}
return booklist;
}
public Collection getBooks(int page, int n) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int sumRs;
int sumPage;
int currRs;
ArrayList<Bean> booklist = new ArrayList<Bean>();
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("select * from 你的表");
rs.last();
sumRs = rs.getRow();
sumPage = (sumRs % n) == 0 ? (sumRs / n) : (sumRs / n + 1);
currRs = (page - 1) * n + 1;
rs.absolute(currRs);
for (int i = 1; i <= n; i++) {
Bean book = new Bean(rs.getInt(1), rs.getString(2), rs
.getString(3), rs.getString(4), rs.getString(5), rs
.getFloat(6), rs.getInt(7), rs.getString(8), rs
.getString(9));
booklist.add(book);
rs.next();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeResultSet(rs);
closeStatement(stmt);
closeConnection(conn);
}
return booklist;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询