resultreader.java

来自「一个Java持久层类库」· Java 代码 · 共 56 行

JAVA
56
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package ActiveObject.core;import java.sql.*;/** * @author tanjiazhang */public class ResultReader {    private Connection connection = null;    private PreparedStatement preparedStatement = null;    private ResultSet resultSet = null;    public ResultReader(String sql, Object... params) throws java.sql.SQLException    {        this.connection = ActiveRecord.getConnection();        this.preparedStatement = connection.prepareStatement(sql);        int index = 1;        for(Object value : params)            preparedStatement.setObject(index, value);        this.resultSet = preparedStatement.executeQuery();    }    /**     * 尝试读一行记录,只有返回值为真时,才允许取出该对象     * @throws java.sql.SQLException     */    public boolean read () throws java.sql.SQLException {        return this.resultSet.next();    }    /**     * 尝试读一行记录,只有返回值为真时,才允许取出该对象     * @throws java.sql.SQLException     */    public ResultSet getResultSet () throws java.sql.SQLException {        return this.resultSet;    }    /**     * 使用DataReader完毕后必须执行close释放资源     * @throws java.sql.SQLException     */    public void close () throws java.sql.SQLException {        this.resultSet.close();        this.preparedStatement.close();        this.connection.close();    }}

⌨️ 快捷键说明

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