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

📄 resultsetimpl.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * @param scale	 *            DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 * 	 * @deprecated	 */	public BigDecimal getBigDecimal(String columnName, int scale)			throws SQLException {		return getBigDecimal(findColumn(columnName), scale);	}	private final BigDecimal getBigDecimalFromString(String stringVal,			int columnIndex, int scale) throws SQLException {		BigDecimal bdVal;		if (stringVal != null) {			if (stringVal.length() == 0) {				bdVal = new BigDecimal(convertToZeroLiteralStringWithEmptyCheck());				try {					return bdVal.setScale(scale);				} catch (ArithmeticException ex) {					try {						return bdVal.setScale(scale, BigDecimal.ROUND_HALF_UP);					} catch (ArithmeticException arEx) {						throw new SQLException(Messages								.getString("ResultSet.Bad_format_for_BigDecimal",										new Object[] { stringVal,												Constants.integerValueOf(columnIndex) }),								SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$					}				}			}			try {				try {					return new BigDecimal(stringVal).setScale(scale);				} catch (ArithmeticException ex) {					try {						return new BigDecimal(stringVal).setScale(scale,								BigDecimal.ROUND_HALF_UP);					} catch (ArithmeticException arEx) {						throw new SQLException(Messages								.getString("ResultSet.Bad_format_for_BigDecimal",										new Object[] { stringVal,												Constants.integerValueOf(columnIndex) }),								SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$					}				}			} catch (NumberFormatException ex) {				if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_BIT) {					long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);					try {						return new BigDecimal(valueAsLong).setScale(scale);					} catch (ArithmeticException arEx1) {						try {							return new BigDecimal(valueAsLong).setScale(scale,									BigDecimal.ROUND_HALF_UP);						} catch (ArithmeticException arEx2) {							throw new SQLException(Messages									.getString("ResultSet.Bad_format_for_BigDecimal",											new Object[] { stringVal,													Constants.integerValueOf(columnIndex) }),									SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$						}					}				}								if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TINY &&						this.connection.getTinyInt1isBit() && this.fields[columnIndex - 1].getLength() == 1) {					return new BigDecimal(stringVal.equalsIgnoreCase("true") ? 1 : 0).setScale(scale);				}								throw new SQLException(Messages						.getString("ResultSet.Bad_format_for_BigDecimal",								new Object[] { stringVal,										Constants.integerValueOf(columnIndex) }),						SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$			}		}				return null;	}	/**	 * A column value can also be retrieved as a binary stream. 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 SQLException	 *                if a database access error occurs	 * 	 * @see getAsciiStream	 * @see getUnicodeStream	 */	public InputStream getBinaryStream(int columnIndex) throws SQLException {		checkRowPos();		if (!this.isBinaryEncoded) {			checkColumnBounds(columnIndex);						int columnIndexMinusOne = columnIndex - 1;						if (this.thisRow.isNull(columnIndexMinusOne)) {				this.wasNullFlag = true;								return null;			}						this.wasNullFlag = false;						return this.thisRow.getBinaryInputStream(columnIndexMinusOne);		}		return getNativeBinaryStream(columnIndex);	}	/**	 * DOCUMENT ME!	 * 	 * @param columnName	 *            DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 */	public InputStream getBinaryStream(String columnName) throws 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.	 */	public java.sql.Blob getBlob(int columnIndex) throws SQLException {		if (!this.isBinaryEncoded) {			checkRowPos();			checkColumnBounds(columnIndex);			int columnIndexMinusOne = columnIndex - 1;						if (this.thisRow.isNull(columnIndexMinusOne)) {				this.wasNullFlag = true;			} else {				this.wasNullFlag = false;			}						if (this.wasNullFlag) {				return null;			}			if (!this.connection.getEmulateLocators()) {				return new Blob(this.thisRow.getColumnValue(columnIndexMinusOne));			}			return new BlobFromLocator(this, columnIndex);		}		return getNativeBlob(columnIndex);	}	/**	 * 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 SQLException	 *                if a database access error occurs	 */	public boolean getBoolean(int columnIndex) throws SQLException {				checkColumnBounds(columnIndex);		//		// MySQL 5.0 and newer have an actual BIT type,		// so we need to check for that here...		//		int columnIndexMinusOne = columnIndex - 1;		Field field = this.fields[columnIndexMinusOne];		if (field.getMysqlType() == MysqlDefs.FIELD_TYPE_BIT) {			return byteArrayToBoolean(columnIndexMinusOne);		}		this.wasNullFlag = false;				int sqlType = field.getSQLType();				switch (sqlType) {		case Types.BIT:		case Types.BOOLEAN:		case Types.TINYINT:		case Types.SMALLINT:		case Types.INTEGER:		case Types.BIGINT:		case Types.DECIMAL:		case Types.NUMERIC:		case Types.REAL:		case Types.FLOAT:		case Types.DOUBLE:			long boolVal = getLong(columnIndex, false);			return (boolVal == -1 || boolVal > 0);		default:			if (this.connection.getPedantic()) {				// Table B-6 from JDBC spec				switch (sqlType) {				case Types.BINARY:				case Types.VARBINARY:				case Types.LONGVARBINARY:				case Types.DATE:				case Types.TIME:				case Types.TIMESTAMP:				case Types.CLOB:				case Types.BLOB:				case Types.ARRAY:				case Types.REF:				case Types.DATALINK:				case Types.STRUCT:				case Types.JAVA_OBJECT:					throw SQLError.createSQLException("Required type conversion not allowed",							SQLError.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST);				}			}					if (sqlType == Types.BINARY ||				sqlType == Types.VARBINARY ||				sqlType == Types.LONGVARBINARY ||				sqlType == Types.BLOB) {				return byteArrayToBoolean(columnIndexMinusOne);			}						if (this.useUsageAdvisor) {				issueConversionViaParsingWarning("getBoolean()", columnIndex,						this.thisRow.getColumnValue(columnIndexMinusOne), this.fields[columnIndex],						new int[] {								MysqlDefs.FIELD_TYPE_BIT,								MysqlDefs.FIELD_TYPE_DOUBLE,								MysqlDefs.FIELD_TYPE_TINY,								MysqlDefs.FIELD_TYPE_SHORT,								MysqlDefs.FIELD_TYPE_LONG,								MysqlDefs.FIELD_TYPE_LONGLONG,								MysqlDefs.FIELD_TYPE_FLOAT });			}					String stringVal = getString(columnIndex);			return getBooleanFromString(stringVal, columnIndex);		}	}	private boolean byteArrayToBoolean(int columnIndexMinusOne) throws SQLException {		Object value = this.thisRow.getColumnValue(columnIndexMinusOne);				if (value == null) {			this.wasNullFlag = true;			return false;		}		this.wasNullFlag = false;		if (((byte[]) value).length == 0) {			return false;		}		byte boolVal = ((byte[]) value)[0];		if (boolVal == (byte)'1') {			return true;		} else if (boolVal == (byte)'0') {			return false;		}				return (boolVal == -1 || boolVal > 0);	}	/**	 * DOCUMENT ME!	 * 	 * @param columnName	 *            DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 */	public boolean getBoolean(String columnName) throws SQLException {		return getBoolean(findColumn(columnName));	}	private final boolean getBooleanFromString(String stringVal, int columnIndex)			throws SQLException {		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;	}	/**	 * 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 SQLException	 *                if a database access error occurs	 */	public byte getByte(int columnIndex) throws SQLException {		if (!this.isBinaryEncoded) {			String stringVal = getString(columnIndex);			if (this.wasNullFlag || (stringVal == null)) {				return 0;			}			return getByteFromString(stringVal, columnIndex);		}		return getNativeByte(columnIndex);	}	/**	 * DOCUMENT ME!	 * 	 * @param columnName	 *            DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 */	public byte getByte(String columnName) throws SQLException {		return getByte(findColumn(columnName));	}	private final byte getByteFromString(String stringVal, int columnIndex)			throws SQLException {		if (stringVal != null && stringVal.length() == 0) {			return (byte) convertToZeroWithEmptyCheck();		}		//		// JDK-6 doesn't like trailing whitespace		//		// Note this isn't a performance issue, other		// than the iteration over the string, as String.trim()		// will return a new string only if whitespace is present		//				if (stringVal == null) {			return 0;		}				stringVal = stringVal.trim(); 				try {			int decimalIndex = stringVal.indexOf(".");						if (decimalIndex != -1) {				double valueAsDouble = Double.parseDouble(stringVal);				if (this.jdbcCompliantTruncationForReads) {					if (valueAsDouble < Byte.MIN_VALUE							|| valueAsDouble > Byte.MAX_VALUE) {						throwRangeException(stringVal, columnIndex,								Types.TINYINT);					}				}				return (byte) valueAsDouble;			}			long valueAsLong = Long.parseLong(stringVal);			if (this.jdbcCompliantTruncationForReads) {				if (valueAsLong < Byte.MIN_VALUE						|| valueAsLong > Byte.MAX_VALUE) {					throwRangeException(String.valueOf(valueAsLong),							columnIndex, Types.TINYINT);				}			}			return (byte) valueAsLong;		} catch (NumberFormatException NFE) {			throw SQLError.createSQLException(					Messages.getString("ResultSet.Value____173")							+ stringVal //$NON-NLS-1$							+ Messages									.getString("ResultSet.___is_out_of_range_[-127,127]_174"),					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		}	}	/**	 * 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 SQLException	 *                if a database access error occurs	 */	public byte[] getBytes(int columnIndex) throws SQLException {		return getBytes(columnIndex, false);	}	protected byte[] getBytes(int columnIndex, boolean noConversion)			throws SQLException {		if (!this.isBinaryEncoded) {			checkRowPos();						checkColumnBounds(columnIndex);			

⌨️ 快捷键说明

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