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

📄 resultset.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		if (index == null) {			index = (Integer) this.fullColumnNameToIndex.get(columnName);		}		if (index != null) {			return index.intValue() + 1;		}		// Try this inefficient way, now		for (int i = 0; i < this.fields.length; i++) {			if (this.fields[i].getName().equalsIgnoreCase(columnName)) {				return i + 1;			} else if (this.fields[i].getFullName()					.equalsIgnoreCase(columnName)) {				return i + 1;			}		}		throw SQLError.createSQLException(Messages.getString("ResultSet.Column____112")				+ columnName				+ Messages.getString("ResultSet.___not_found._113"), //$NON-NLS-1$ //$NON-NLS-2$				SQLError.SQL_STATE_COLUMN_NOT_FOUND);	}	/**	 * JDBC 2.0	 * 	 * <p>	 * Moves to the first row in the result set.	 * </p>	 * 	 * @return true if on a valid row, false if no rows in the result set.	 * 	 * @exception SQLException	 *                if a database-access error occurs, or result set type is	 *                TYPE_FORWARD_ONLY.	 */	public boolean first() throws SQLException {		checkClosed();		if (this.rowData.isEmpty()) {			return false;		}		if (this.onInsertRow) {			this.onInsertRow = false;		}		if (this.doingUpdates) {			this.doingUpdates = false;		}		this.rowData.beforeFirst();		this.thisRow = this.rowData.next();		return true;	}	/**	 * JDBC 2.0 Get an array column.	 * 	 * @param i	 *            the first column is 1, the second is 2, ...	 * 	 * @return an object representing an SQL array	 * 	 * @throws SQLException	 *             if a database error occurs	 * @throws NotImplemented	 *             DOCUMENT ME!	 */	public java.sql.Array getArray(int i) throws SQLException {		checkColumnBounds(i);				throw new NotImplemented();	}	/**	 * JDBC 2.0 Get an array column.	 * 	 * @param colName	 *            the column name	 * 	 * @return an object representing an SQL array	 * 	 * @throws SQLException	 *             if a database error occurs	 * @throws NotImplemented	 *             DOCUMENT ME!	 */	public java.sql.Array getArray(String colName) throws SQLException {		return getArray(findColumn(colName));	}	/**	 * A column value can be retrieved as a stream of ASCII characters and then	 * read in chunks from the stream. This method is particulary suitable for	 * retrieving large LONGVARCHAR values. The JDBC driver will do any	 * necessary conversion from the database format into ASCII.	 * 	 * <p>	 * <B>Note:</B> All the data in the returned stream must be read prior to	 * getting the value of any other column. The next call to a get method	 * implicitly closes the stream. Also, a stream may return 0 for available()	 * whether there is data available or not.	 * </p>	 * 	 * @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 one byte ASCII characters. If the value is SQL NULL	 *         then the result is null	 * 	 * @exception SQLException	 *                if a database access error occurs	 * 	 * @see getBinaryStream	 */	public InputStream getAsciiStream(int columnIndex) throws SQLException {		checkRowPos();		if (!this.isBinaryEncoded) {			return getBinaryStream(columnIndex);		}		return getNativeBinaryStream(columnIndex);	}	/**	 * DOCUMENT ME!	 * 	 * @param columnName	 *            DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 */	public InputStream getAsciiStream(String columnName) throws SQLException {		return getAsciiStream(findColumn(columnName));	}	/**	 * JDBC 2.0 Get the value of a column in the current row as a	 * java.math.BigDecimal object.	 * 	 * @param columnIndex	 *            the first column is 1, the second is 2, ...	 * 	 * @return the column value (full precision); if the value is SQL NULL, the	 *         result is null	 * 	 * @exception SQLException	 *                if a database-access error occurs.	 */	public BigDecimal getBigDecimal(int columnIndex) throws SQLException {		if (!this.isBinaryEncoded) {			String stringVal = getString(columnIndex);			BigDecimal val;			if (stringVal != null) {				if (stringVal.length() == 0) {										val = new BigDecimal(							convertToZeroLiteralStringWithEmptyCheck());					return val;				}				try {					val = new BigDecimal(stringVal);					return val;				} catch (NumberFormatException ex) {					throw SQLError.createSQLException(Messages							.getString("ResultSet.Bad_format_for_BigDecimal",									new Object[] { stringVal,											new Integer(columnIndex) }),							SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$				}			}			return null;		}		return getNativeBigDecimal(columnIndex);	}	/**	 * Get the value of a column in the current row as a java.math.BigDecimal	 * object	 * 	 * @param columnIndex	 *            the first column is 1, the second is 2...	 * @param scale	 *            the number of digits to the right of the decimal	 * 	 * @return the column value; if the value is SQL NULL, null	 * 	 * @exception SQLException	 *                if a database access error occurs	 * 	 * @deprecated	 */	public BigDecimal getBigDecimal(int columnIndex, int scale)			throws SQLException {		if (!this.isBinaryEncoded) {			String stringVal = getString(columnIndex);			BigDecimal val;			if (stringVal != null) {				if (stringVal.length() == 0) {					val = new BigDecimal(							convertToZeroLiteralStringWithEmptyCheck());					try {						return val.setScale(scale);					} catch (ArithmeticException ex) {						try {							return val									.setScale(scale, BigDecimal.ROUND_HALF_UP);						} catch (ArithmeticException arEx) {							throw SQLError.createSQLException(									Messages											.getString("ResultSet.Bad_format_for_BigDecimal____124") //$NON-NLS-1$											+ stringVal											+ Messages													.getString("ResultSet.___in_column__125")											+ columnIndex											+ "(" //$NON-NLS-1$											+ this.fields[columnIndex - 1]											+ ").",									SQLError.SQL_STATE_ILLEGAL_ARGUMENT);						}					}				}				try {					val = new BigDecimal(stringVal);				} catch (NumberFormatException ex) {					if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_BIT) {						long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);						val = new BigDecimal(valueAsLong);					} else {						throw SQLError.createSQLException(Messages							.getString("ResultSet.Bad_format_for_BigDecimal",									new Object[] { new Integer(columnIndex),											stringVal }),							SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$						}				}				try {					return val.setScale(scale);				} catch (ArithmeticException ex) {					try {						return val.setScale(scale, BigDecimal.ROUND_HALF_UP);					} catch (ArithmeticException arithEx) {						throw SQLError.createSQLException(Messages.getString(								"ResultSet.Bad_format_for_BigDecimal",								new Object[] { new Integer(columnIndex),										stringVal }),								SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$					}				}			}			return null;		}		return getNativeBigDecimal(columnIndex, scale);	}	/**	 * JDBC 2.0 Get the value of a column in the current row as a	 * java.math.BigDecimal object.	 * 	 * @param columnName	 *            the name of the column to retrieve the value from	 * 	 * @return the BigDecimal value in the column	 * 	 * @throws SQLException	 *             if an error occurs	 */	public BigDecimal getBigDecimal(String columnName) throws SQLException {		return getBigDecimal(findColumn(columnName));	}	/**	 * DOCUMENT ME!	 * 	 * @param columnName	 *            DOCUMENT ME!	 * @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,												new Integer(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,												new Integer(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,													new Integer(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,										new Integer(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) {			byte[] b = getBytes(columnIndex);			if (b != null) {				return new ByteArrayInputStream(b);			}			return null;		}		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);			if (this.thisRow[columnIndex - 1] == null) {				this.wasNullFlag = true;			} else {				this.wasNullFlag = false;			}						if (this.wasNullFlag) {				return null;			}			if (!this.connection.getEmulateLocators()) {				return new Blob((byte[]) this.thisRow[columnIndex - 1]);			}			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.

⌨️ 快捷键说明

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