求解:java.sql.SQLException:Before start of result set

来源:百度知道 编辑:UC知道 时间:2024/05/26 09:21:28
我知道正常出现这种情况应该是要使用result.next();

不过我已经在查询数据的时候制定指针的位置了,怎么还有问题?
(我是在JFrame中使用分页出现的问题)

public static int RowCount;
public static int PageCount;
public static int PageSize = 20 ;
public static int Page=0;
public static int S;

DB CODE:

ResultSet rs = stmt.executeQuery("select * from table");

rs.last();
RowCount = rs.getRow();
// 记算总页数
PageCount = ( RowCount + PageSize - 1)/PageSize;
rs.beforeFirst();

前台:
while ( S < PageSize && !rs.isAfterLast) {
int id = rs.getInt("id");
int name = rs.getString("name");
}

因为我已经将指针指到第一条上
如果在while中加入rs.next(),到是能显示出结果,就从第二条开始,也不分页了!

如果我把DB CODE 中的
rs.beforeFirst();

改成
// 调整待显示的页码
if ( Page > PageCount)
Page = PageCount;
if (Constants.PageCount > 0) {
// 将记录指针定位到待显示页的第一条记录上
rs.absolute(( Page - 1) * PageSize + 1);

while(rs.next()){
rs.get...;
}
循环里直接取就行了。至于分页,我没看你代码,建议你用存储过程,传页面参数进去取出来显示就行。

多说一句,我都是用存储过程处理业务逻辑。
希望对你有帮助