⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultsetdatalistchunk.java

📁 以前写的通用数据库接口
💻 JAVA
字号:
package util.database.datalist;import java.sql.*;/** * ResultSetDataListChunk实现了DataList接口,针对ResultSet使用。 * * 表示一个查询结果ResultSet集和的一个子集。 * @author Michael Zeng * @version 1.0 September 23, 2002 */public class ResultSetDataListChunk implements DataList{    private ResultSetDataList dl = null;    private int start = 0, count = 0, indexOfChunk = -1;    /**     * package构造函数。     *     * @param _dl 全部结果的集和,_dl.size()必须大于0     * @param _start 起始位置,从0开始,最大值_dl.size() - 1     * @param _count 子集的个数,从1开始     * @throws Exception     */    ResultSetDataListChunk(DataList _dl, int _start, int _count)            throws Exception    {        dl = (ResultSetDataList)_dl;        start = Math.abs(_start);        count = Math.abs(_count);        if(dl.size() == 0)            throw new Exception("需要操作的结果集为空!");        if(start >= dl.size())            throw new Exception("起始位置大于结果集的大小!");        if(start + count > dl.size())            count = dl.size() - start;    }    /**     * 取出指定位置查询结果子集中的字段值,放到一个字符串数组中并返回。     * 功能类似于java.util.List.get(int)     *     * @param index 查询结果子集的索引     * @return String[] 结果中的字段值数组     *     * @throws SQLException     */    public String[] get(int index) throws SQLException    {        if(index <0 || index >= count)            throw new IndexOutOfBoundsException("指定的索引越界!");        String[] value =  dl.get(start + index);        indexOfChunk = index;        return value;    }    /**     * 检查查询结果的子集集和是否为空集合     *     * @return boolean true表示空集合     * @throws SQLException     */    public boolean isEmpty() throws SQLException    {        if(count == 0)            return true;        else            return false;    }    /**     * 检查是否还有下一个查询结果     *     * @return boolean true表示有下一个     */    public boolean hasNext()    {        return (indexOfChunk + 1 < count);    }    /**     * 检查在指定位置上是否有查询结果     *     * @param index 查询结果的索引     * @return boolean true表示有查询结果     * @throws SQLException     */    public boolean isElementExist(int index) throws SQLException    {        if(index >= count)            return false;        else            return dl.isElementExist(start + index);    }    /**     * 把游标放到指定的位置上,功能类似于java.sql.ResultSet.absolute(int)     *     * @param index 指定的位置,从0开始     * @return boolean true表示操作成功     * @throws SQLException     */    public boolean absolute(int index) throws SQLException    {        if(index >= count)            return false;        boolean isSuccess = dl.absolute(start + index);        //如果成功,改变当前chunk的索引        if(isSuccess)   indexOfChunk = index;        return isSuccess;    }    /**     * 把游标放到查询结果子集Chunk的最前面     *     * @throws SQLException     */    public void beforeFirst() throws SQLException    {        indexOfChunk = -1;        //start == 0表示从父集合的起始位置开始        if(start == 0)            dl.beforeFirst();        else            dl.absolute(start - 1);    }    /**     * 把游标放到查询结果子集的第一个,功能类似于java.sql.ResultSet.first()     *     * @return boolean true表示移动成功     * @throws SQLException     */    public boolean first() throws SQLException    {        return dl.absolute(start);    }    /**     * 把游标放到查询结果子集的最后一个,功能类似于java.sql.ResultSet.last()     *     * @return boolean true表示移动成功     * @throws SQLException     */    public boolean last() throws SQLException    {        return dl.absolute(start + count -1);    }    /**     * 取得整个查询结果子集的大小,功能类似于java.util.List.size()     *     * @return size 查询结果子集的大小     */    public int size()    {        return count;    }    /**     * 提供一个可以遍历查询结果的对象,功能类似于java.util.List.iterator()     *     * @return DataListIterator 可以遍历查询结果的对象     * @throws Exception     */    public DataListIterator iterator() throws Exception    {        return new ResultSetDataListIterator(this);    }}

⌨️ 快捷键说明

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