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

📄 resultset.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public long getLong(String columnName) throws 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 SQLException if a database access error occurs     */    public java.sql.ResultSetMetaData getMetaData() throws SQLException {    	checkClosed();    	        return new com.mysql.jdbc.ResultSetMetaData(this.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 SQLException if a database access error occurs     */    public Object getObject(int columnIndex) throws SQLException {        checkRowPos();        try {            if (this.thisRow[columnIndex - 1] == null) {            	this.wasNullFlag = true;                return null;            }        } catch (ArrayIndexOutOfBoundsException aioobEx) {            throw new SQLException(Messages.getString(                    "ResultSet.Column_Index_out_of_range",                    new Object[] {                        new Integer(columnIndex),                        new Integer(this.fields.length)                    }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$        }        this.wasNullFlag = false;        Field field;        field = this.fields[columnIndex - 1];        //        // If they come from a binary-encode result set,        // no need to create another new object to represent        // the value, just return it directly, unless it's        // a byte[], which means it could be a string or blob.        //        if (this.isBinaryEncoded &&                !(this.thisRow[columnIndex - 1] instanceof byte[])) {        	        	        	//        	// Special case here...If this is a 'bit' type, it will actually have         	// been returned as an Integer by the server...        	//        	if (field.getSQLType() == Types.BIT) {        		// valueOf would be nicer here, but it isn't            	// present in JDK-1.3.1, which is what the CTS            	// uses.        		return new Boolean(getBoolean(columnIndex));        	}        	            Object columnValue = this.thisRow[columnIndex - 1];            if (columnValue == null) {                this.wasNullFlag = true;                return null;            }            return columnValue;        }        switch (field.getSQLType()) {        case Types.BIT:        	if (field.getMysqlType() == MysqlDefs.FIELD_TYPE_BIT         			&& field.getLength() > 0) {        		return getBytes(columnIndex);        	}        	        	// valueOf would be nicer here, but it isn't        	// present in JDK-1.3.1, which is what the CTS        	// uses.            return new Boolean(getBoolean(columnIndex));        case Types.TINYINT:            return new Integer(getByte(columnIndex));        case Types.SMALLINT:            return new Integer(getInt(columnIndex));        case Types.INTEGER:            if (!field.isUnsigned()) {                return new Integer(getInt(columnIndex));            }            return new Long(getLong(columnIndex));        case Types.BIGINT:            if (!field.isUnsigned()) {                return new Long(getLong(columnIndex));            }            String stringVal = getString(columnIndex);            if (stringVal == null) {                return null;            }            try {                return new BigInteger(stringVal);            } catch (NumberFormatException nfe) {                throw new SQLException(Messages.getString(                        "ResultSet.Bad_format_for_BigInteger",                        new Object[] { new Integer(columnIndex), stringVal }),                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$            }        case Types.DECIMAL:        case Types.NUMERIC:            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 SQLException(Messages.getString(                            "ResultSet.Bad_format_for_BigDecimal____86") //$NON-NLS-1$                         +stringVal +                        Messages.getString("ResultSet.___in_column__87") +                        columnIndex + "(" //$NON-NLS-1$                         + this.fields[columnIndex - 1] + ").",                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);                }                return val;            }            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:        	if (!field.isOpaqueBinary()) {        		return getString(columnIndex);        	}        		        	return getBytes(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);                                if (this.connection.getAutoDeserialize()) {                	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(Messages.getString(	                                    "ResultSet.Class_not_found___91") //$NON-NLS-1$	                                 +cnfe.toString() +	                                Messages.getString(	                                    "ResultSet._while_reading_serialized_object_92")); //$NON-NLS-1$	                        } catch (IOException ex) {	                            obj = data; // not serialized?	                        }	                    }	                }		                return obj;                }                                return data;            }        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>     *     * @param columnName is the SQL name of the column     *     * @return a Object holding the column value     *     * @exception SQLException if a database access error occurs     */    public Object getObject(String columnName) throws SQLException {        return getObject(findColumn(columnName));    }    /**     * JDBC 2.0 Returns the value of column i as a Java object.  Use the map to     * determine the class from which to construct data of SQL structured and     * distinct types.     *     * @param i the first column is 1, the second is 2, ...     * @param map the mapping from SQL type names to Java classes     *     * @return an object representing the SQL value     *     * @throws SQLException because this is not implemented     */    public Object getObject(int i, java.util.Map map) throws SQLException {        return getObject(i);    }    /**     * JDBC 2.0 Returns the value of column i as a Java object.  Use the map to     * determine the class from which to construct data of SQL structured and     * distinct types.     *     * @param colName the column name     * @param map the mapping from SQL type names to Java classes     *     * @return an object representing the SQL value     *     * @throws SQLException as this is not implemented     */    public Object getObject(String colName, java.util.Map map)        throws SQLException {        return getObject(findColumn(colName), map);    }    /**     * JDBC 2.0 Get a REF(&lt;structured-type&gt;) column.     *     * @param i the first column is 1, the second is 2, ...     *     * @return an object representing data of an SQL REF type     *     * @throws SQLException as this is not implemented     * @throws NotImplemented DOCUMENT ME!     */    public java.sql.Ref getRef(int i) throws SQLException {        throw new NotImplemented();    }    /**     * JDBC 2.0 Get a REF(&lt;structured-type&gt;) column.     *     * @param colName the column name     *     * @return an object representing data of an SQL REF type     *     * @throws SQLException as this method is not implemented.     * @throws NotImplemented DOCUMENT ME!     */    public java.sql.Ref getRef(String colName) throws SQLException {        throw new NotImplemented();    }    /**     * JDBC 2.0     *     * <p>     * Determine the current row number.  The first row is number 1, the second     * number 2, etc.     * </p>     *     * @return the current row number, else return 0 if there is no current row     *     * @exception SQLException if a database-access error occurs.     */    public int getRow() throws SQLException {    	checkClosed();    	        int currentRowNumber = this.rowData.getCurrentRowNumber();        int row = 0;        // Non-dynamic result sets can be interrogated        // for this information        if (!this.rowData.isDynamic()) {            if ((currentRowNumber < 0) || this.rowData.isAfterLast() ||            		this.rowData.isEmpty()) {                row = 0;            } else {                row = currentRowNumber + 1;            }        } else {            // dynamic (streaming) can not            row = currentRowNumber + 1;        }        return row;    }    /**     * Get the value of a column in the current row as a Java short.     *     * @param columnIndex the first column is 1, the second is 2,...     *     * @return the column value; 0 if SQL NULL     *     * @exception SQLException if a database access error occurs     */    public short getShort(int columnIndex) throws SQLException {        if (!this.isBinaryEncoded) {            if (this.connection.getUseFastIntParsing()) {                checkRowPos();                try {                    if (this.thisRow[columnIndex - 1] == null) {                        this.wasNullFlag = true;                    } else {                        this.wasNullFlag = false;                    }                } catch (NullPointerException E) {                    this.wasNullFlag = true;                } catch (ArrayIndexOutOfBoundsException aioobEx) {                    throw new SQLException(Messages.getString(                            "ResultSet.Column_Index_out_of_range",                            new Object[] {                                new Integer(columnIndex),                                new Integer(this.fields.length)                            }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$                }                if (this.wasNullFlag) {                    return 0;                }                byte[] shortAsBytes = (byte[]) this.thisRow[columnIndex - 1];                boolean needsFullParse = false;                for (int i = 0; i < shortAsBytes.length; i++) {                    if (((char) shortAsBytes[i] == 'e') ||                            ((char) shortAsBytes[i] == 'E')) {                        

⌨️ 快捷键说明

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