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

📄 resultsetrowmapper.java

📁 以前写的通用数据库接口
💻 JAVA
字号:
package util.database.datalist;import java.sql.*;/** * ResultSetRowMapper实现了RowMapper接口,针对ResultSet使用。 * * 把一个ResultSet中的字段值取出,放到一个字符串数组中。 * @author Michael Zeng * @version 1.0 September 20, 2002 */public class ResultSetRowMapper implements RowMapper{    private String[] columns = new String[0];    /**     * package构造函数     *     * @param rs 指定的ResultSet     * @throws SQLException     */    ResultSetRowMapper(ResultSet rs) throws SQLException    {        this.setColumns(rs);    }    /**     * 取出指定的ResultSet中的被查询字段的名称数组     *     * @return String[] 被查询字段的名称数组     */    public String[] getRowColumns()    {        return columns;    }    /**     * 取出ResultSet中的字段值,放到一个字符串数组中并返回。     * 不进行ResultSet的有效性检查,必须有调用者负责检查。     *     * @param obj 指定的查询结果对象,必须是ResultSet对象     * @return String[] 字段值字符串数组     * @throws SQLException     */    public String[] rowMap(Object obj) throws SQLException    {        ResultSet rs = (ResultSet)obj;        //设置私有变量保存被查询字段        if(this.columns == null || this.columns.length == 0)            this.setColumns(rs);        String[] values = new String[this.columns.length];        for (int i = 0; i < this.columns.length; i++)        {            values[i] = rs.getString(this.columns[i]);        }        return values;    }    /**     * helper方法,取出指定的ResultSet中的被查询字段的名称数组,     * 并且设置私有变量保存被查询字段。     *     * @param rs 指定的ResultSet     * @throws SQLException     */    private void setColumns(ResultSet rs) throws SQLException    {        ResultSetMetaData rsmd = rs.getMetaData();        int columnCount = rsmd.getColumnCount();        this.columns = new String[columnCount];        for (int i = 0; i < columnCount; i++)        {            this.columns[i] = rsmd.getColumnName(i + 1);        }     }}

⌨️ 快捷键说明

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