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

📄 resultset.java

📁 网上销售系统是目前 Internet 上广泛使用的在线系统之一。 网上售书这是信息社会发展的必然要求。国际互联网的开通
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @exception SQLException if a database-access error occurs.
     */
    public boolean isFirst() throws SQLException {
        if (Driver.TRACE) {
            Object[] args = {  };
            Debug.methodCall(this, "isFirst", args);
        }

        boolean b = rowData.isFirst();

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

        return b;
    }

    /**
     * Get the value of a column in the current row as a Java float.
     *
     * @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 float getFloat(int columnIndex) throws java.sql.SQLException {
        checkRowPos();

        String val = null;

        try {
            val = getString(columnIndex);

            if ((val != null) && (val.length() != 0)) {
                float f = Float.parseFloat(val);

                return f;
            } else {
                return 0;
            }
        } catch (NumberFormatException nfe) {
            try {
                // To do: warn on under/overflow?
                return (float) Double.parseDouble(val);
            } catch (NumberFormatException newNfe) {
                ; // ignore, it's not a number
            }

            throw new SQLException("Invalid value for getFloat() - '" + val
                + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }
    }

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

    /**
     * Get the value of a column in the current row as a Java int.
     *
     * @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 int getInt(int columnIndex) throws java.sql.SQLException {
        String val = null;

        try {
            val = getString(columnIndex);

            if ((val != null) && (val.length() != 0)) {
                if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)
                        && (val.indexOf(".") == -1)) {
                    return Integer.parseInt(val);
                } else {
                    // Convert floating point
                    return (int) (Double.parseDouble(val));
                }
            } else {
                return 0;
            }
        } catch (NumberFormatException nfe) {
            try {
                // To do: warn on under/overflow?
                return (int) Double.parseDouble(val);
            } catch (NumberFormatException newNfe) {
                ; // ignore, it's not a number
            }

            throw new SQLException("Invalid value for getInt() - '" + val + "'",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }
    }

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

    /**
     * JDBC 2.0
     * 
     * <p>
     * Determine if the cursor is on the last row of the result set. Note:
     * Calling isLast() may be expensive since the JDBC driver might need to
     * fetch ahead one row in order to determine whether the current row is
     * the last row in the result set.
     * </p>
     *
     * @return true if on the last row, false otherwise.
     *
     * @exception SQLException if a database-access error occurs.
     */
    public boolean isLast() throws SQLException {
        if (Driver.TRACE) {
            Object[] args = {  };
            Debug.methodCall(this, "isLast", args);
        }

        boolean b = rowData.isLast();

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

        return b;
    }

    /**
     * Get the value of a column in the current row as a Java long.
     *
     * @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 long getLong(int columnIndex) throws java.sql.SQLException {
        checkRowPos();

        String val = null;

        try {
            val = getString(columnIndex);

            if ((val != null) && (val.length() != 0)) {
                if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)) {
                    return Long.parseLong(val);
                } else {
                    // Convert floating point
                    return Double.doubleToLongBits(Double.parseDouble(val));
                }
            } else {
                return 0;
            }
        } catch (NumberFormatException nfe) {
            try {
                // To do: warn on under/overflow?
                return (long) Double.parseDouble(val);
            } catch (NumberFormatException newNfe) {
                ; // ignore, it's not a number
            }

            throw new SQLException("Invalid value for getLong() - '" + val
                + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }
    }

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

    /**
     * The numbers, types and properties of a ResultSet's columns are provided
     * by the getMetaData method
     *
     * @return a description of the ResultSet's columns
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public java.sql.ResultSetMetaData getMetaData()
        throws java.sql.SQLException {
        return new com.mysql.jdbc.ResultSetMetaData(fields);
    }

    /**
     * Get the value of a column in the current row as a Java object
     * 
     * <p>
     * This method will return the value of the given column as a Java object.
     * The type of the Java object will be the default Java Object type
     * corresponding to the column's SQL type, following the mapping specified
     * in the JDBC specification.
     * </p>
     * 
     * <p>
     * This method may also be used to read database specific abstract data
     * types.
     * </p>
     *
     * @param columnIndex the first column is 1, the second is 2...
     *
     * @return a Object holding the column value
     *
     * @exception java.sql.SQLException if a database access error occurs
     * @throws SQLException DOCUMENT ME!
     */
    public Object getObject(int columnIndex) throws java.sql.SQLException {
        checkRowPos();

        if (Driver.TRACE) {
            Object[] args = { new Integer(columnIndex) };
            Debug.methodCall(this, "getObject", args);
        }

        try {
            if (thisRow[columnIndex - 1] == null) {
                wasNullFlag = true;

                return null;
            }
        } catch (ArrayIndexOutOfBoundsException aioobEx) {
            throw new java.sql.SQLException("Column Index out of range ( "
                + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER);
        }

        wasNullFlag = false;

        Field field;
        field = fields[columnIndex - 1];

        switch (field.getSQLType()) {
        case Types.BIT:
            return new Boolean(getBoolean(columnIndex));

        case Types.TINYINT:

            return new Integer(getInt(columnIndex));
           
        case Types.SMALLINT:
        	
            return new Integer(getInt(columnIndex));
           
        case Types.INTEGER:

            if (field.isUnsigned()) {
                return new Long(getLong(columnIndex));
            } else {
                return new Integer(getInt(columnIndex));
            }

        case Types.BIGINT:

            if (field.isUnsigned()) {
                return getBigDecimal(columnIndex);
            } else {
                return new Long(getLong(columnIndex));
            }

        case Types.DECIMAL:
        case Types.NUMERIC:

            String stringVal = getString(columnIndex);
            BigDecimal val;

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

                    return val;
                }

                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);
                }

                return val;
            } else {
                return null;
            }

        case Types.REAL:
            return new Float(getFloat(columnIndex));

        case Types.FLOAT:
        case Types.DOUBLE:
            return new Double(getDouble(columnIndex));

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return getString(columnIndex);

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:

            if (!field.isBlob()) {
                return getString(columnIndex);
            } else if (!field.isBinary()) {
                return getString(columnIndex);
            } else {
                byte[] data = getBytes(columnIndex);
                Object obj = data;

                if ((data != null) && (data.length >= 2)) {
                    if ((data[0] == -84) && (data[1] == -19)) {
                        // Serialized object?
                        try {
                            ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
                            ObjectInputStream objIn = new ObjectInputStream(bytesIn);
                            obj = objIn.readObject();
                            objIn.close();
                            bytesIn.close();
                        } catch (ClassNotFoundException cnfe) {
                            throw new SQLException("Class not found: "
                                + cnfe.toString()
                                + " while reading serialized object");
                        } catch (IOException ex) {
                            obj = data; // not serialized?
                        }
                    }
                }

                return obj;
            }

        case Types.DATE:
            return getDate(columnIndex);

        case Types.TIME:
            return getTime(columnIndex);

        case Types.TIMESTAMP:
            return getTimestamp(columnIndex);

        default:
            return getString(columnIndex);
        }
    }

    /**
     * Get the value of a column in the current row as a Java object
     * 
     * <p>
     * This method will return the value of the given column as a Java object.
     * The type of the Java object will be the default Java Object type
     * corresponding to the column's SQL type, following the mapping specified
     * in the JDBC specification.
     * </p>
     * 
     * <p>
     * This method may also be used to read database specific abstract data
     * types.
     * </p>
     *

⌨️ 快捷键说明

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