哭啊,刚才点错了,本来就写好了,强烈建议增加自动保存功能!!!!!!!!!!!!!!
封装类的初始化程序如:










sql可能是这样:



在jsp页面代码如下:























这样的做法是这样的:将所有记录的信息都保存在ResultSet中,然后在页面上通过循环控制某条记录是否显示在页面上。这样的弊端就是将所有记录的信息都查询到内存中,如果记录集很大的话,势必影响性能。
最近看了别人bbs系统中对于分页的实现,也是jsp版本的,原理如下:
int pageSize = 50;
int currentPage;
int startNum = (pageSize-1)*currentPage+1;
int endNum = pageSize*currentPage;
int currentPage;
int startNum = (pageSize-1)*currentPage+1;
int endNum = pageSize*currentPage;
public String getList()
...{
Connection conn = null;
ResultSet rs = null;
PreparedStatement stmt = null;
...{
Connection conn = null;
ResultSet rs = null;
PreparedStatement stmt = null;
conn = DatabaseBean.getConnection();
String s = "";
StringBuffer sb = new StringBuffer("");
try...{
String strSQL = "select id from (select id,rownum rn from logManage order by id asc) where rowNum between ? and ? ";
stmt = conn.prepareStatement(strSQL);
stmt.setInt(1,startNum);
stmt.setInt(2,endNum);
rs = stmt.executeQuery();
while(rs != null && rs.next())
...{
sb.append(id);
sb.append(",");
}
rs.close();
rs = null;
}catch(Exception e)...{
}finally...{
try...{
if(conn != null)
conn.close();
}catch(Exception ex)...{}
}
String s = "";
StringBuffer sb = new StringBuffer("");
try...{
String strSQL = "select id from (select id,rownum rn from logManage order by id asc) where rowNum between ? and ? ";
stmt = conn.prepareStatement(strSQL);
stmt.setInt(1,startNum);
stmt.setInt(2,endNum);
rs = stmt.executeQuery();
while(rs != null && rs.next())
...{
sb.append(id);
sb.append(",");
}
rs.close();
rs = null;
}catch(Exception e)...{
}finally...{
try...{
if(conn != null)
conn.close();
}catch(Exception ex)...{}
}
s = sb.substring(0,sb.length()-1);
return s;
}
return s;
}
这样做的道理是,将当前也要显示的记录的id号先查询出来,然后在jsp页面中的sql可以这样写:

这样保证了查询的结果集都是当前页面的一个结果集,因为每页所显示的记录数都很有限,所以即使数据量很大也是没有关系。
因为对于缓存的处理还没有什么概念,所以不在本文的思考范围内。
这只是个人在学习过程中的一些个人思考,有错的地方请指出,联系我:aimer311@sina.com