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

📄 resultset.java

📁 mysql的jdbc驱动
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			while (warningToAppendTo.getNextWarning() != null) {				warningToAppendTo = warningToAppendTo.getNextWarning();			}			warningToAppendTo.setNextWarning(warning);		}	}	/**	 * JDBC 2.0	 * 	 * <p>	 * Moves to the end of the result set, just after the last row. Has no	 * effect if the result set contains no rows.	 * </p>	 * 	 * @exception SQLException	 *                if a database-access error occurs, or result set type is	 *                TYPE_FORWARD_ONLY.	 */	public void afterLast() throws SQLException {		checkClosed();		if (this.onInsertRow) {			this.onInsertRow = false;		}		if (this.doingUpdates) {			this.doingUpdates = false;		}		if (this.rowData.size() != 0) {			this.rowData.afterLast();			this.thisRow = null;		}	}	/**	 * JDBC 2.0	 * 	 * <p>	 * Moves to the front of the result set, just before the first row. Has no	 * effect if the result set contains no rows.	 * </p>	 * 	 * @exception SQLException	 *                if a database-access error occurs, or result set type is	 *                TYPE_FORWARD_ONLY	 */	public void beforeFirst() throws SQLException {		checkClosed();		if (this.onInsertRow) {			this.onInsertRow = false;		}		if (this.doingUpdates) {			this.doingUpdates = false;		}		if (this.rowData.size() == 0) {			return;		}		this.rowData.beforeFirst();		this.thisRow = null;	}	// ---------------------------------------------------------------------	// Traversal/Positioning	// ---------------------------------------------------------------------	/**	 * Builds a hash between column names and their indices for fast retrieval.	 */	protected void buildIndexMapping() throws SQLException {		int numFields = this.fields.length;		this.columnNameToIndex = new HashMap(numFields);		this.fullColumnNameToIndex = new HashMap(numFields);		// We do this in reverse order, so that the 'first' column		// with a given name ends up as the final mapping in the		// hashtable...		//		// Quoting the JDBC Spec:		//		// "Column names used as input to getter		// methods are case insensitive. When a getter method is called with a		// column		// name and several columns have the same name, the value of the first		// matching column will be returned. "		//		for (int i = numFields - 1; i >= 0; i--) {			Integer index = new Integer(i);			String columnName = this.fields[i].getName();			String fullColumnName = this.fields[i].getFullName();			if (columnName != null) {				this.columnNameToIndex.put(columnName, index);				this.columnNameToIndex.put(columnName.toUpperCase(), index);				this.columnNameToIndex.put(columnName.toLowerCase(), index);			}			if (fullColumnName != null) {				this.fullColumnNameToIndex.put(fullColumnName, index);				this.fullColumnNameToIndex.put(fullColumnName.toUpperCase(),						index);				this.fullColumnNameToIndex.put(fullColumnName.toLowerCase(),						index);			}		}		// set the flag to prevent rebuilding...		this.hasBuiltIndexMapping = true;	}	/**	 * JDBC 2.0 The cancelRowUpdates() method may be called after calling an	 * updateXXX() method(s) and before calling updateRow() to rollback the	 * updates made to a row. If no updates have been made or updateRow() has	 * already been called, then this method has no effect.	 * 	 * @exception SQLException	 *                if a database-access error occurs, or if called when on	 *                the insert row.	 * @throws NotUpdatable	 *             DOCUMENT ME!	 */	public void cancelRowUpdates() throws SQLException {		throw new NotUpdatable();	}	/**	 * Ensures that the result set is not closed	 * 	 * @throws SQLException	 *             if the result set is closed	 */	protected final synchronized void checkClosed() throws SQLException {		if (this.isClosed) {			throw new SQLException(					Messages							.getString("ResultSet.Operation_not_allowed_after_ResultSet_closed_144"), //$NON-NLS-1$					SQLError.SQL_STATE_GENERAL_ERROR);		}	}	/**	 * Checks if columnIndex is within the number of columns in this result set.	 * 	 * @param columnIndex	 *            the index to check	 * 	 * @throws SQLException	 *             if the index is out of bounds	 */	protected final void checkColumnBounds(int columnIndex) throws SQLException {		if ((columnIndex < 1) || (columnIndex > this.fields.length)) {			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.profileSql || this.useUsageAdvisor) {			this.columnUsed[columnIndex - 1] = true;		}	}	/**	 * Ensures that the cursor is positioned on a valid row and that the result	 * set is not closed	 * 	 * @throws SQLException	 *             if the result set is not in a valid state for traversal	 */	protected void checkRowPos() throws SQLException {		checkClosed();		if (!this.rowData.isDynamic() && (this.rowData.size() == 0)) {			throw new SQLException(					Messages							.getString("ResultSet.Illegal_operation_on_empty_result_set"),					SQLError.SQL_STATE_GENERAL_ERROR);		}		if (this.rowData.isBeforeFirst()) {			throw new SQLException(Messages					.getString("ResultSet.Before_start_of_result_set_146"),					SQLError.SQL_STATE_GENERAL_ERROR); //$NON-NLS-1$		}		if (this.rowData.isAfterLast()) {			throw new SQLException(Messages					.getString("ResultSet.After_end_of_result_set_148"),					SQLError.SQL_STATE_GENERAL_ERROR); //$NON-NLS-1$		}	}	/**	 * We can't do this ourselves, otherwise the contract for	 * Statement.getMoreResults() won't work correctly.	 */	protected void clearNextResult() {		this.nextResultSet = null;	}	/**	 * After this call, getWarnings returns null until a new warning is reported	 * for this ResultSet	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void clearWarnings() throws SQLException {		this.warningChain = null;	}	/**	 * In some cases, it is desirable to immediately release a ResultSet	 * database and JDBC resources instead of waiting for this to happen when it	 * is automatically closed. The close method provides this immediate	 * release.	 * 	 * <p>	 * <B>Note:</B> A ResultSet is automatically closed by the Statement the	 * Statement that generated it when that Statement is closed, re-executed,	 * or is used to retrieve the next result from a sequence of multiple	 * results. A ResultSet is also automatically closed when it is garbage	 * collected.	 * </p>	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public synchronized void close() throws SQLException {		realClose(true);	}	/**	 * @return	 */	private int convertToZeroWithEmptyCheck() throws SQLException {		if (this.connection.getEmptyStringsConvertToZero()) {			return 0;		}		throw new SQLException("Can't convert empty string ('') to numeric",				SQLError.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST);	}	//	// Note, row data is linked between these two result sets	//	protected final ResultSet copy() throws SQLException {		ResultSet rs = new ResultSet(this.catalog, this.fields, this.rowData,				this.connection, this.owningStatement);		return rs;	}	/**	 * JDBC 2.0 Delete the current row from the result set and the underlying	 * database. Cannot be called when on the insert row.	 * 	 * @exception SQLException	 *                if a database-access error occurs, or if called when on	 *                the insert row.	 * @throws NotUpdatable	 *             DOCUMENT ME!	 */	public void deleteRow() throws SQLException {		throw new NotUpdatable();	}	/**	 * @param columnIndex	 * @param stringVal	 * @param mysqlType	 * @return	 * @throws SQLException	 */	private String extractStringFromNativeColumn(int columnIndex, int mysqlType)			throws SQLException {		int columnIndexMinusOne = columnIndex - 1;		if (this.thisRow[columnIndexMinusOne] instanceof String) {			return (String) this.thisRow[columnIndexMinusOne];		}		if (this.thisRow[columnIndexMinusOne] == null) {			return null;		}		String stringVal = null;		if ((this.connection != null) && this.connection.getUseUnicode()) {			try {				String encoding = this.fields[columnIndexMinusOne]						.getCharacterSet();				if (encoding == null) {					stringVal = new String(							(byte[]) this.thisRow[columnIndexMinusOne]);				} else {					SingleByteCharsetConverter converter = this.connection							.getCharsetConverter(encoding);					if (converter != null) {						stringVal = converter								.toString((byte[]) this.thisRow[columnIndexMinusOne]);					} else {						stringVal = new String(								(byte[]) this.thisRow[columnIndexMinusOne],								encoding);					}				}			} catch (java.io.UnsupportedEncodingException E) {				throw new SQLException(						Messages								.getString("ResultSet.Unsupported_character_encoding____138") //$NON-NLS-1$								+ this.connection.getEncoding() + "'.", "0S100");			}		} else {			stringVal = StringUtils					.toAsciiString((byte[]) this.thisRow[columnIndexMinusOne]);		}				return stringVal;	}	private synchronized Date fastDateCreate(Calendar cal, int year, int month,			int day) {		if (cal == null) {			if (this.fastDateCal == null) {				this.fastDateCal = new GregorianCalendar(Locale.US);				this.fastDateCal.setTimeZone(this.getDefaultTimeZone());			}			cal = this.fastDateCal;		}		return TimeUtil.fastDateCreate(cal, year, month, day);	}	private synchronized Time fastTimeCreate(Calendar cal, int hour,			int minute, int second) {		if (cal == null) {			if (this.fastDateCal == null) {				this.fastDateCal = new GregorianCalendar(Locale.US);				this.fastDateCal.setTimeZone(this.getDefaultTimeZone());			}			cal = this.fastDateCal;		}		return TimeUtil.fastTimeCreate(cal, hour, minute, second);	}	private synchronized Timestamp fastTimestampCreate(Calendar cal, int year,			int month, int day, int hour, int minute, int seconds,			int secondsPart) {		if (cal == null) {			if (this.fastDateCal == null) {				this.fastDateCal = new GregorianCalendar(Locale.US);				this.fastDateCal.setTimeZone(this.getDefaultTimeZone());			}			cal = this.fastDateCal;		}		return TimeUtil.fastTimestampCreate(cal, year, month, day, hour,				minute, seconds, secondsPart);	}	/*	/**	 * Required by JDBC spec	 */	/*	protected void finalize() throws Throwable {		if (!this.isClosed) {			realClose(false);		}	}	*/	// --------------------------JDBC 2.0-----------------------------------	// ---------------------------------------------------------------------	// Getter's and Setter's	// ---------------------------------------------------------------------	/**	 * Map a ResultSet column name to a ResultSet column index	 * 	 * @param columnName	 *            the name of the column	 * 	 * @return the column index	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public synchronized int findColumn(String columnName) throws SQLException {		Integer index;		if (!this.hasBuiltIndexMapping) {			buildIndexMapping();		}		index = (Integer) this.columnNameToIndex.get(columnName);		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 new SQLException(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 {		throw new NotImplemented();	}	/**	 * JDBC 2.0 Get an array column.	 * 

⌨️ 快捷键说明

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