resultsetreader.java

来自「j2ee源码」· Java 代码 · 共 50 行

JAVA
50
字号
/*
 * Created on 2005/11/14
 */
package com.leeman.common.data;

import java.sql.ResultSet;
/**
 * @author Dennis
 */
public class ResultSetReader {
	
	private int startRecord;
	private ResultSet rs;
	private int maxRecords;
	
	private int currentRecord;
	
	//startRecord: The zero-based record number to start with.
	//maxRecords: The maximum number of records to retrieve.
	public ResultSetReader(ResultSet rs, int startRecord, int maxRecords)
	{
		this.startRecord = startRecord;
		this.rs = rs;
		this.maxRecords = maxRecords; 
		currentRecord = 0;
	}
		
	public boolean next() throws java.sql.SQLException
	{
		currentRecord ++;
		if (currentRecord == 1){
			if (startRecord == 0){
				return rs.next();
			}
			else{
				return rs.absolute(startRecord+1);
			}
		}
		else
		{
			if (currentRecord <= maxRecords || maxRecords == 0){
				return rs.next();
			}
			else{
				return false;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?