分页算法问题 急!!

michael_2043 2006-03-07 09:44:53
帮我看一下这段程序为什么不能分页查询???
start 是起始页,step是步长
public List executePageQuery(String sql, String bean, int start, int step) {
rs = null;
List list = new ArrayList();
int starts = 1;
try {
if (conn == null) {
this.getConnection();
}
if (conn != null) {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}

Class mybean = Class.forName(bean);
Object myobj = null;
Class[] myclass = { "".getClass() };

ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
myobj = mybean.newInstance();
if (starts >= (start - 1) * step && starts < step * start) {
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
String colname = rsmd.getColumnName(i);
StringBuffer col = new StringBuffer("set");
col.append(colname.replace(colname.charAt(0), Character
.toUpperCase(colname.charAt(0))));
col.replace(4, col.length(), col.substring(4)
.toLowerCase());
Method m = mybean.getMethod(col.toString(), myclass);
m.invoke(myobj, new Object[] { rs.getString(colname) });
}
list.add(myobj);
}
}
starts++;
System.out.println(starts);
} catch (SQLException e) {
this.closeConnection();
System.err.println("db.executeQuery:" + e.getMessage());
} catch (ClassNotFoundException ec) {
System.err.println("mydb():" + ec.getMessage());
} catch (Exception ee) {
System.err.println("myerr==" + ee.getMessage());
System.out.println("==" + ee.toString());
} finally {
this.closeConnection();
}
return list;
}

}
...全文
57 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧