📄 resultset.java
字号:
} /** * 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); } checkClosed(); 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 { 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 { checkClosed(); 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 Boolean.valueOf(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> * * @param columnName is the SQL name of the column * * @return a Object holding the column value * * @exception java.sql.SQLException if a database access error occurs */ public Object getObject(String columnName) throws java.sql.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(<structured-type>) 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(<structured-type>) column. * * @param colName the column name * * @return an object representing data of an SQL REF type * * @throws SQLException as this method is not implemented.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -