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

📄 abstractresultset.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.sourceforge.jtds.jdbc;

import java.io.*;
import java.math.BigDecimal;
import java.sql.*;
import java.text.*;
import java.util.Calendar;

/**
 * This class implements all of the get and update methods, which are delegated to the row object.
 * <p>
 * This is so we can easily subclass this object to provide say cached result sets, or cursor-based
 * result sets.
 *
 * @author   chris
 * @author   Alin Sinpalean
 * @created  17 March 2001
 * @version  $Id: AbstractResultSet.java,v 1.2 2002/10/22 11:22:51 alin_sinpalean Exp $
 */
public abstract class AbstractResultSet implements ResultSet
{
    public final static String cvsVersion = "$Id: AbstractResultSet.java,v 1.2 2002/10/22 11:22:51 alin_sinpalean Exp $";

    public final static int DEFAULT_FETCH_SIZE = 100;

    /**
     * Number of rows to fetch once. An implementation may ignore this.
     */
    protected int fetchSize = DEFAULT_FETCH_SIZE;

    /**
     * The <code>ResultSet</code>'s warning chain.
     */
    protected SQLWarningChain warningChain = null;

    /**
     * The <code>ResultSet</code>'s meta data.
     */
    ResultSetMetaData metaData = null;

    /**
     * Used to format numeric values when scale is specified.
     */
    private static NumberFormat f = NumberFormat.getInstance();

    /**
     * Returns the <code>Context</code> of the <code>ResultSet</code> instance. A
     * <code>Context</code> holds information about the <code>ResultSet</code>'s columns.
     */
    public abstract Context getContext();

    /**
     * Returns the current row in the <code>ResultSet</code>, or <code>null</code> if there is no
     * current row.
     *
     * @exception  SQLException  if an SQL error occurs or there is no current row
     */
    public abstract PacketRowResult currentRow() throws SQLException;

    public ResultSetMetaData getMetaData() throws SQLException
    {
        if( metaData == null )
            metaData = new TdsResultSetMetaData(getContext().getColumnInfo());
        return metaData;
    }

    public java.io.InputStream getAsciiStream(String columnName) throws SQLException
    {
        return getAsciiStream(findColumn(columnName));
    }

    public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException
    {
        return getBigDecimal(findColumn(columnName), scale);
    }

    public java.io.InputStream getBinaryStream(String columnName) throws SQLException
    {
        return getBinaryStream(findColumn(columnName));
    }

    public boolean getBoolean(String columnName) throws SQLException
    {
        return getBoolean(findColumn(columnName));
    }

    public byte getByte(String columnName) throws SQLException
    {
        return getByte(findColumn(columnName));
    }

    public byte[] getBytes(String columnName) throws SQLException
    {
        return getBytes(findColumn(columnName));
    }

    public java.sql.Date getDate(String columnName) throws SQLException
    {
        return getDate(findColumn(columnName));
    }

    public double getDouble(String columnName) throws SQLException
    {
        return getDouble(findColumn(columnName));
    }

    public float getFloat(String columnName) throws SQLException
    {
        return getFloat(findColumn(columnName));
    }

    public int getInt(String columnName) throws SQLException
    {
        return getInt(findColumn(columnName));
    }

    public long getLong(String columnName) throws SQLException
    {
        return getLong(findColumn(columnName));
    }

    public Object getObject(String columnName) throws SQLException
    {
        return getObject(findColumn(columnName));
    }

    public short getShort(String columnName) throws SQLException
    {
        return getShort(findColumn(columnName));
    }

    public String getString(String columnName) throws SQLException
    {
        return getString(findColumn(columnName));
    }

    public java.sql.Time getTime(String columnName) throws SQLException
    {
        return getTime(findColumn(columnName));
    }

    public java.sql.Timestamp getTimestamp(String columnName) throws SQLException
    {
        return getTimestamp(findColumn(columnName));
    }

    public java.io.InputStream getUnicodeStream(String columnName) throws SQLException
    {
        return getUnicodeStream(findColumn(columnName));
    }

    public Ref getRef(String colName) throws SQLException
    {
        return getRef(findColumn(colName));
    }

    public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException
    {
        return getTimestamp(findColumn(columnName), cal);
    }

    public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException
    {
        return getDate(findColumn(columnName), cal);
    }

    public java.sql.Time getTime(String columnName, Calendar cal) throws SQLException
    {
        return getTime(findColumn(columnName), cal);
    }

    public short getShort(int index) throws SQLException
    {
        return (short)getLong(index);
    }

    public Object getObject(String colName, java.util.Map map) throws SQLException
    {
        return getObject(findColumn(colName), map);
    }

    public Blob getBlob(String colName) throws SQLException
    {
        return getBlob(findColumn(colName));
    }

    public Clob getClob(String colName) throws SQLException
    {
        return getClob(findColumn(colName));
    }

    public Array getArray(String colName) throws SQLException
    {
        return getArray(findColumn(colName));
    }

    public float getFloat(int index) throws SQLException
    {
        return (float)getDouble(index);
    }

    public int getInt(int index) throws SQLException
    {
        return (int)getLong(index);
    }

    public java.io.InputStream getAsciiStream(int index) throws SQLException
    {
        String val = getString(index);
        if( val == null )
            return null;

        try
        {
            return new ByteArrayInputStream(val.getBytes("ASCII"));
        }
        catch (UnsupportedEncodingException ue)
        {
            // plain impossible with encoding ASCII
            return null;
        }
    }

    public BigDecimal getBigDecimal(int index, int scale) throws SQLException
    {
        return currentRow().getBigDecimal(index, scale);
    }

    public java.io.InputStream getBinaryStream(int index) throws SQLException
    {
        byte[] bytes = getBytes(index);
        if( bytes != null )
            return new ByteArrayInputStream(bytes);
        return null;
    }

    public boolean getBoolean(int index) throws SQLException
    {
        return currentRow().getBoolean(index);
    }

    public byte getByte(int index) throws SQLException
    {
        return (byte) getLong(index);
    }

    public byte[] getBytes(int index) throws SQLException
    {
        return currentRow().getBytes(index);
    }

    public java.sql.Date getDate(int index) throws SQLException
    {
        java.sql.Date result = null;
        java.sql.Timestamp tmp = getTimestamp(index);

        if( tmp != null )
            result = new java.sql.Date(tmp.getTime());
        return result;
    }

    public double getDouble(int index) throws SQLException
    {
        return currentRow().getDouble(index);
    }

    public long getLong(int index) throws SQLException
    {
        return currentRow().getLong(index);
    }

    public Object getObject(int index) throws SQLException
    {
        if( currentRow() == null )
            throw new SQLException("No current row in the result set.");
        return currentRow().getObject(index);
    }

    public String getString(int index) throws SQLException
    {
        Object tmp = getObject(index);

        if( tmp == null )
            return null;
        // Binary value, generate hex string
        else if( tmp instanceof byte[] )
        {
            byte[] b = (byte[])tmp;
            StringBuffer buf = new StringBuffer(2*b.length);

            for( int i=0; i<b.length; i++ )
            {
                int n=((int)b[i])&0xFF, v=n/16;
                buf.append((char)(v<10 ? '0'+v : 'A'+v-10));
                v = n%16;
                buf.append((char)(v<10 ? '0'+v : 'A'+v-10));
            }
            return buf.toString();
        }
        else
            return tmp.toString();
    }

    public java.sql.Time getTime(int index) throws SQLException
    {
        java.sql.Time result = null;
        java.sql.Timestamp tmp = getTimestamp(index);

        if( tmp != null )
            result = new java.sql.Time(tmp.getTime());
        return result;
    }

    public java.io.Reader getCharacterStream(int index) throws SQLException
    {
        String val = getString(index);

        if( val == null )
            return null;
        return new java.io.StringReader(val);
    }

    public java.io.Reader getCharacterStream(String columnName) throws SQLException
    {
        return getCharacterStream(findColumn(columnName));
    }

    public BigDecimal getBigDecimal(int index) throws SQLException
    {
        return currentRow().getBigDecimal(index);
    }

    public BigDecimal getBigDecimal(String columnName) throws SQLException
    {
        return currentRow().getBigDecimal(findColumn(columnName));
    }

⌨️ 快捷键说明

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