分页算法问题 急!!

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;
}

}
...全文
36 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-07 09:44
社区公告
暂无公告