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

📄 resultset.java

📁 一个网上书店程序!实现网上购书结算等! 由jsp+javabean+mysql组成! 功能很完善
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

        if (Driver.TRACE) {
            Debug.returnValue(this, "isBeforeFirst", new Boolean(b));
        }

        return b;
    }

    /**
     * Get the value of a column in the current row as a java.math.BigDecimal
     * object
     *
     * @param columnIndex the first column is 1, the second is 2...
     * @param scale the number of digits to the right of the decimal
     *
     * @return the column value; if the value is SQL NULL, null
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public BigDecimal getBigDecimal(int columnIndex, int scale)
        throws java.sql.SQLException {
        String stringVal = getString(columnIndex);
        BigDecimal val;

        if (stringVal != null) {
            if (stringVal.length() == 0) {
                val = new BigDecimal(0);

                return val.setScale(scale);
            }

            try {
                val = new BigDecimal(stringVal);
            } catch (NumberFormatException ex) {
                throw new java.sql.SQLException("Bad format for BigDecimal '"
                    + stringVal + "' in column " + columnIndex + "("
                    + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
            }

            try {
                return val.setScale(scale);
            } catch (ArithmeticException ex) {
                throw new java.sql.SQLException("Bad format for BigDecimal '"
                    + stringVal + "' in column " + columnIndex + "("
                    + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
            }
        }

        return null;
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnName DOCUMENT ME!
     * @param scale DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public BigDecimal getBigDecimal(String columnName, int scale)
        throws java.sql.SQLException {
        return getBigDecimal(findColumn(columnName), scale);
    }

    /**
     * JDBC 2.0 Get the value of a column in the current row as a
     * java.math.BigDecimal object.
     *
     * @param columnIndex the first column is 1, the second is 2, ...
     *
     * @return the column value (full precision); if the value is SQL NULL, the
     *         result is null
     *
     * @exception SQLException if a database-access error occurs.
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
        String stringVal = getString(columnIndex);
        BigDecimal val;

        if (stringVal != null) {
            if (stringVal.length() == 0) {
                val = new BigDecimal(0);

                return val;
            }

            try {
                val = new BigDecimal(stringVal);

                return val;
            } catch (NumberFormatException ex) {
                throw new java.sql.SQLException("Bad format for BigDecimal '"
                    + stringVal + "' in column " + columnIndex + "("
                    + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
            }
        }

        return null;
    }

    /**
     * JDBC 2.0 Get the value of a column in the current row as a
     * java.math.BigDecimal object.
     *
     * @param columnName the name of the column to retrieve the value from
     *
     * @return the BigDecimal value in the column
     *
     * @throws SQLException if an error occurs
     */
    public BigDecimal getBigDecimal(String columnName)
        throws SQLException {
        return getBigDecimal(findColumn(columnName));
    }

    /**
     * A column value can also be retrieved as a binary strea.  This method is
     * suitable for retrieving LONGVARBINARY values.
     *
     * @param columnIndex the first column is 1, the second is 2...
     *
     * @return a Java InputStream that delivers the database column value as a
     *         stream of bytes.  If the value is SQL NULL, then the result is
     *         null
     *
     * @exception java.sql.SQLException if a database access error occurs
     *
     * @see getAsciiStream
     * @see getUnicodeStream
     */
    public InputStream getBinaryStream(int columnIndex)
        throws java.sql.SQLException {
        checkRowPos();

        byte[] b = getBytes(columnIndex);

        if (b != null) {
            return new ByteArrayInputStream(b);
        }

        return null;
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnName DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public InputStream getBinaryStream(String columnName)
        throws java.sql.SQLException {
        return getBinaryStream(findColumn(columnName));
    }

    /**
     * JDBC 2.0 Get a BLOB column.
     *
     * @param columnIndex the first column is 1, the second is 2, ...
     *
     * @return an object representing a BLOB
     *
     * @throws SQLException if an error occurs.
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public java.sql.Blob getBlob(int columnIndex) throws SQLException {
        checkRowPos();

        if ((columnIndex < 1) || (columnIndex > fields.length)) {
            throw new java.sql.SQLException("Column Index out of range ( "
                + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER);
        }

        try {
            if (thisRow[columnIndex - 1] == null) {
                wasNullFlag = true;
            } else {
                wasNullFlag = false;
            }
        } catch (NullPointerException ex) {
            wasNullFlag = true;
        }

        if (wasNullFlag) {
            return null;
        }

        return new Blob(thisRow[columnIndex - 1]);
    }

    /**
     * JDBC 2.0 Get a BLOB column.
     *
     * @param colName the column name
     *
     * @return an object representing a BLOB
     *
     * @throws SQLException if an error occurs.
     */
    public java.sql.Blob getBlob(String colName) throws SQLException {
        return getBlob(findColumn(colName));
    }

    /**
     * Get the value of a column in the current row as a Java boolean
     *
     * @param columnIndex the first column is 1, the second is 2...
     *
     * @return the column value, false for SQL NULL
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public boolean getBoolean(int columnIndex) throws java.sql.SQLException {
        String stringVal = getString(columnIndex);

        if ((stringVal != null) && (stringVal.length() > 0)) {
            int c = Character.toLowerCase(stringVal.charAt(0));

            return ((c == 't') || (c == 'y') || (c == '1')
            || stringVal.equals("-1"));
        }

        return false;
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnName DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public boolean getBoolean(String columnName) throws java.sql.SQLException {
        return getBoolean(findColumn(columnName));
    }

    /**
     * Get the value of a column in the current row as a Java byte.
     *
     * @param columnIndex the first column is 1, the second is 2,...
     *
     * @return the column value; 0 if SQL NULL
     *
     * @exception java.sql.SQLException if a database access error occurs
     * @throws SQLException DOCUMENT ME!
     */
    public byte getByte(int columnIndex) throws java.sql.SQLException {
        checkRowPos();

        try {
            if (thisRow[columnIndex - 1] == null) {
                wasNullFlag = true;
            } else {
                wasNullFlag = false;
            }
        } catch (NullPointerException E) {
            wasNullFlag = true;
        }

        if (wasNullFlag) {
            return 0;
        }

        Field field = fields[columnIndex - 1];

        switch (field.getMysqlType()) {
        case MysqlDefs.FIELD_TYPE_DECIMAL:
        case MysqlDefs.FIELD_TYPE_TINY:
        case MysqlDefs.FIELD_TYPE_SHORT:
        case MysqlDefs.FIELD_TYPE_LONG:
        case MysqlDefs.FIELD_TYPE_FLOAT:
        case MysqlDefs.FIELD_TYPE_DOUBLE:
        case MysqlDefs.FIELD_TYPE_LONGLONG:
        case MysqlDefs.FIELD_TYPE_INT24:

            try {
                String stringVal = getString(columnIndex);
                int decimalIndex = stringVal.indexOf(".");

                // Strip off the decimals
                if (decimalIndex != -1) {
                    stringVal = stringVal.substring(0, decimalIndex);
                }

                return Byte.parseByte(stringVal);
            } catch (NumberFormatException NFE) {
                throw new SQLException("Value '" + getString(columnIndex)
                    + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
            }

        default:

            try {
                String stringVal = getString(columnIndex);

                int decimalIndex = stringVal.indexOf(".");

                // Strip off the decimals
                if (decimalIndex != -1) {
                    stringVal = stringVal.substring(0, decimalIndex);
                }

                return Byte.parseByte(stringVal);
            } catch (NumberFormatException NFE) {
                throw new SQLException("Value '" + getString(columnIndex)
                    + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
            }

            // FIXME: JDBC-Compliance test is broken, wants to convert string->byte(num)
            //return _thisRow[columnIndex - 1][0];
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnName DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public byte getByte(String columnName) throws java.sql.SQLException {
        return getByte(findColumn(columnName));
    }

    /**
     * Get the value of a column in the current row as a Java byte array.
     * 
     * <p>
     * <b>Be warned</b> If the blob is huge, then you may run out of memory.
     * </p>
     *
     * @param columnIndex the first column is 1, the second is 2, ...
     *
     * @return the column value; if the value is SQL NULL, the result is null
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public byte[] getBytes(int columnIndex) throws java.sql.SQLException {
        checkRowPos();

        try {
            if (thisRow[columnIndex - 1] == null) {
                wasNullFlag = true;
            } else {
                wasNullFlag = false;
            }
        } catch (NullPointerException E) {
            wasNullFlag = true;
        } catch (ArrayIndexOutOfBoundsException aioobEx) {
            throw new java.sql.SQLException("Column Index out of range ( "
                + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER);
        }

        if (wasNullFlag) {
            return null;
        } else {
            return thisRow[columnIndex - 1];
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnName DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public byte[] getBytes(String columnName) throws java.sql.SQLException {
        return getBytes(findColumn(columnName));
    }

    //--------------------------JDBC 2.0-----------------------------------
    //---------------------------------------------------------------------
    // Getter's and Setter's
    //---------------------------------------------------------------------

    /**
     * JDBC 2.0
     * 
     * <p>
     * Get the value of a column in the current row as a java.io.Reader.
     * </p>

⌨️ 快捷键说明

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