?? resultset.java
字號(hào):
* set type is TYPE_FORWARD_ONLY. */ public boolean absolute(int row) throws SQLException { checkClosed(); boolean b; if (this.rowData.size() == 0) { b = false; } else { if (row == 0) { throw SQLError.createSQLException( Messages .getString("ResultSet.Cannot_absolute_position_to_row_0_110"), //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } if (this.onInsertRow) { this.onInsertRow = false; } if (this.doingUpdates) { this.doingUpdates = false; } if (row == 1) { b = first(); } else if (row == -1) { b = last(); } else if (row > this.rowData.size()) { afterLast(); b = false; } else { if (row < 0) { // adjust to reflect after end of result set int newRowPosition = this.rowData.size() + row + 1; if (newRowPosition <= 0) { beforeFirst(); b = false; } else { b = absolute(newRowPosition); } } else { row--; // adjust for index difference this.rowData.setCurrentRow(row); this.thisRow = this.rowData.getAt(row); b = true; } } } return b; } /** * 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 TreeMap(String.CASE_INSENSITIVE_ORDER); this.fullColumnNameToIndex = new TreeMap(String.CASE_INSENSITIVE_ORDER); // 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); } if (fullColumnName != null) { this.fullColumnNameToIndex.put(fullColumnName, 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 void checkClosed() throws SQLException { if (this.isClosed) { throw SQLError.createSQLException( 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)) { throw SQLError.createSQLException(Messages.getString( "ResultSet.Column_Index_out_of_range_low", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } else if ((columnIndex > this.fields.length)) { throw SQLError.createSQLException(Messages.getString( "ResultSet.Column_Index_out_of_range_high", 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 SQLError.createSQLException( Messages .getString("ResultSet.Illegal_operation_on_empty_result_set"), SQLError.SQL_STATE_GENERAL_ERROR); } if (this.rowData.isBeforeFirst()) { throw SQLError.createSQLException(Messages .getString("ResultSet.Before_start_of_result_set_146"), SQLError.SQL_STATE_GENERAL_ERROR); //$NON-NLS-1$ } if (this.rowData.isAfterLast()) { throw SQLError.createSQLException(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 void close() throws SQLException { realClose(true); } /** * @return */ private int convertToZeroWithEmptyCheck() throws SQLException { if (this.connection.getEmptyStringsConvertToZero()) { return 0; } throw SQLError.createSQLException("Can't convert empty string ('') to numeric", SQLError.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST); } private String convertToZeroLiteralStringWithEmptyCheck() throws SQLException { if (this.connection.getEmptyStringsConvertToZero()) { return "0"; } throw SQLError.createSQLException("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; } protected void redefineFieldsForDBMD(Field[] f) { this.fields = f; for (int i = 0; i < this.fields.length; i++) { this.fields[i].setUseOldNameMetadata(true); this.fields[i].setConnection(this.connection); } } /** * 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; this.wasNullFlag = false; if (this.thisRow[columnIndexMinusOne] instanceof String) { return (String) this.thisRow[columnIndexMinusOne]; } if (this.thisRow[columnIndexMinusOne] == null) { this.wasNullFlag = true; return null; } this.wasNullFlag = false; 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 SQLError.createSQLException( 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) { createCalendarIfNeeded(); cal = this.fastDateCal; } boolean useGmtMillis = this.connection.getUseGmtMillisForDatetimes(); return TimeUtil.fastDateCreate(useGmtMillis, useGmtMillis ? getGmtCalendar() : null, cal, year, month, day); } private synchronized Time fastTimeCreate(Calendar cal, int hour, int minute, int second) throws SQLException { if (cal == null) { createCalendarIfNeeded(); 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) { createCalendarIfNeeded(); cal = this.fastDateCal; } boolean useGmtMillis = this.connection.getUseGmtMillisForDatetimes(); return TimeUtil.fastTimestampCreate(useGmtMillis, useGmtMillis ? getGmtCalendar() : null, 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);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -