📄 resultset.java
字号:
new Integer(columnIndex), new Integer(this.fields.length) }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.wasNullFlag) { return 0; } byte[] intAsBytes = (byte[]) this.thisRow[columnIndex - 1]; boolean needsFullParse = false; for (int i = 0; i < intAsBytes.length; i++) { if (((char) intAsBytes[i] == 'e') || ((char) intAsBytes[i] == 'E')) { needsFullParse = true; break; } } if (!needsFullParse) { try { return parseIntWithOverflowCheck(columnIndex, intAsBytes, null); } catch (NumberFormatException nfe) { try { return parseIntAsDouble(columnIndex, new String( intAsBytes)); } catch (NumberFormatException newNfe) { ; // ignore, it's not a number } throw new SQLException(Messages.getString( "ResultSet.Invalid_value_for_getInt()_-____74") + new String(intAsBytes) //$NON-NLS-1$ +"'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } } 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); } // Convert floating point return parseIntAsDouble(columnIndex, val); } return 0; } catch (NumberFormatException nfe) { try { return parseIntAsDouble(columnIndex, val); } catch (NumberFormatException newNfe) { ; // ignore, it's not a number } throw new SQLException(Messages.getString( "ResultSet.Invalid_value_for_getInt()_-____74") + val //$NON-NLS-1$ +"'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } return getNativeInt(columnIndex); } private short parseShortWithOverflowCheck(int columnIndex, byte[] valueAsBytes, String valueAsString) throws NumberFormatException, SQLException { short shortValue = 0; if (valueAsBytes == null && valueAsString == null) { return 0; } if (valueAsBytes != null) { shortValue = StringUtils.getShort(valueAsBytes); } else { shortValue = Short.parseShort(valueAsString); } if (this.connection.getJdbcCompliantTruncation()) { if (shortValue == Short.MIN_VALUE || shortValue == Short.MAX_VALUE) { long valueAsLong = Long.parseLong(valueAsString == null ? new String(valueAsBytes) : valueAsString); if (valueAsLong < Short.MIN_VALUE || valueAsLong > Short.MAX_VALUE) { throwRangeException(valueAsString == null ? new String(valueAsBytes) : valueAsString, columnIndex, Types.SMALLINT); } } } return shortValue; } private short parseShortAsDouble(int columnIndex, String val) throws NumberFormatException, SQLException { if (val == null) { return 0; } double valueAsDouble = Double.parseDouble(val); if (this.connection.getJdbcCompliantTruncation()) { if (valueAsDouble < Short.MIN_VALUE || valueAsDouble > Short.MAX_VALUE) { throwRangeException(String.valueOf(valueAsDouble), columnIndex, Types.SMALLINT); } } return (short) valueAsDouble; } private int parseIntWithOverflowCheck(int columnIndex, byte[] valueAsBytes, String valueAsString) throws NumberFormatException, SQLException { int intValue = 0; if (valueAsBytes == null && valueAsString == null) { return 0; } if (valueAsBytes != null) { intValue = StringUtils.getInt(valueAsBytes); } else { intValue = Integer.parseInt(valueAsString); } if (this.connection.getJdbcCompliantTruncation()) { if (intValue == Integer.MIN_VALUE || intValue == Integer.MAX_VALUE) { long valueAsLong = Long.parseLong(valueAsString == null ? new String(valueAsBytes) : valueAsString); if (valueAsLong < Integer.MIN_VALUE || valueAsLong > Integer.MAX_VALUE) { throwRangeException(valueAsString == null ? new String(valueAsBytes) : valueAsString, columnIndex, Types.INTEGER); } } } return intValue; } private int parseIntAsDouble(int columnIndex, String val) throws NumberFormatException, SQLException { if (val == null) { return 0; } double valueAsDouble = Double.parseDouble(val); if (this.connection.getJdbcCompliantTruncation()) { if (valueAsDouble < Integer.MIN_VALUE || valueAsDouble > Integer.MAX_VALUE) { throwRangeException(String.valueOf(valueAsDouble), columnIndex, Types.INTEGER); } } return (int) valueAsDouble; } private long parseLongWithOverflowCheck(int columnIndex, byte[] valueAsBytes, String valueAsString) throws NumberFormatException, SQLException { long longValue = 0; if (valueAsBytes == null && valueAsString == null) { return 0; } if (valueAsBytes != null) { longValue = StringUtils.getLong(valueAsBytes); } else { longValue = Long.parseLong(valueAsString); } if (this.connection.getJdbcCompliantTruncation()) { if (longValue == Integer.MIN_VALUE || longValue == Integer.MAX_VALUE) { double valueAsDouble = Double.parseDouble(valueAsString == null ? new String(valueAsBytes) : valueAsString); if (valueAsDouble < Long.MIN_VALUE || valueAsDouble > Long.MAX_VALUE) { throwRangeException(valueAsString == null ? new String(valueAsBytes) : valueAsString, columnIndex, Types.BIGINT); } } } return longValue; } private long parseLongAsDouble(int columnIndex, String val) throws NumberFormatException, SQLException { if (val == null) { return 0; } double valueAsDouble = Double.parseDouble(val); if (this.connection.getJdbcCompliantTruncation()) { if (valueAsDouble < Long.MIN_VALUE || valueAsDouble > Long.MAX_VALUE) { throwRangeException(val, columnIndex, Types.BIGINT); } } return (long) valueAsDouble; } /** * @param truncation */ private synchronized void addAWarning(SQLWarning warning) { if (this.warningChain == null) { this.warningChain = warning; } else { SQLWarning warningToAppendTo = this.warningChain; while (warningToAppendTo.getNextWarning() != null) { warningToAppendTo = warningToAppendTo.getNextWarning(); } warningToAppendTo.setNextWarning(warning); } } private void throwRangeException(String valueAsString, int columnIndex, int jdbcType) throws SQLException { String datatype = null; switch (jdbcType) { case Types.TINYINT: datatype = "TINYINT"; break; case Types.SMALLINT: datatype = "SMALLINT"; break; case Types.INTEGER: datatype = "INTEGER"; break; case Types.BIGINT: datatype = "BIGINT"; break; case Types.REAL: datatype = "REAL"; break; case Types.FLOAT: datatype = "FLOAT"; break; case Types.DOUBLE: datatype = "DOUBLE"; break; case Types.DECIMAL: datatype = "DECIMAL"; break; default: datatype = " (JDBC type '" + jdbcType + "')"; } throw new SQLException("'" + valueAsString + "' in column '" + columnIndex + "' is outside valid range for the datatype " + datatype + ".", SQLError.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE); } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SQLException DOCUMENT ME! */ public int getInt(String columnName) throws 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 { checkClosed(); return this.rowData.isLast(); } /** * 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 SQLException if a database access error occurs */ public long getLong(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[] longAsBytes = (byte[]) this.thisRow[columnIndex - 1]; boolean needsFullParse = false; for (int i = 0; i < longAsBytes.length; i++) { if (((char) longAsBytes[i] == 'e') || ((char) longAsBytes[i] == 'E')) { needsFullParse = true; break; } } if (!needsFullParse) { try { return parseLongWithOverflowCheck(columnIndex, longAsBytes, null); } catch (NumberFormatException nfe) { try { // To do: Warn of over/underflow??? return parseLongAsDouble(columnIndex, new String(longAsBytes)); } catch (NumberFormatException newNfe) { // ; // ignore, it's not a number } throw new SQLException(Messages.getString( "ResultSet.Invalid_value_for_getLong()_-____79") + new String(longAsBytes) //$NON-NLS-1$ +"'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } } String val = null; try { val = getString(columnIndex); if ((val != null) && (val.length() != 0)) { if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)) { return parseLongWithOverflowCheck(columnIndex, null, val); } //Convert floating point return parseLongAsDouble(columnIndex, val); } return 0; } catch (NumberFormatException nfe) { try { return parseLongAsDouble(columnIndex, val); } catch (NumberFormatException newNfe) { // ; // ignore, it's not a number } throw new SQLException(Messages.getString( "ResultSet.Invalid_value_for_getLong()_-____79") + val //$NON-NLS-1$ +"'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } return getNativeLong(columnIndex); } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SQLException DOCUMENT ME! */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -