📄 resultsetimpl.java
字号:
} } public void populateCachedMetaData(CachedResultSetMetaData cachedMetaData) throws SQLException { cachedMetaData.fields = this.fields; cachedMetaData.columnNameToIndex = this.columnLabelToIndex; cachedMetaData.fullColumnNameToIndex = this.fullColumnNameToIndex; cachedMetaData.metadata = getMetaData(); } public void initializeFromCachedMetaData(CachedResultSetMetaData cachedMetaData) { this.fields = cachedMetaData.fields; this.columnLabelToIndex = cachedMetaData.columnNameToIndex; this.fullColumnNameToIndex = cachedMetaData.fullColumnNameToIndex; this.hasBuiltIndexMapping = true; } /** * 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.isNull(columnIndexMinusOne)) { this.wasNullFlag = true; return null; } this.wasNullFlag = false; String encoding = this.fields[columnIndexMinusOne] .getCharacterSet(); return this.thisRow.getString(columnIndex - 1, encoding, this.connection); } protected synchronized Date fastDateCreate(Calendar cal, int year, int month, int day) { if (this.useLegacyDatetimeCode) { return TimeUtil.fastDateCreate(year, month, day, cal); } if (cal == null) { createCalendarIfNeeded(); cal = this.fastDateCal; } boolean useGmtMillis = this.connection.getUseGmtMillisForDatetimes(); return TimeUtil.fastDateCreate(useGmtMillis, useGmtMillis ? getGmtCalendar() : cal, cal, year, month, day); } protected synchronized Time fastTimeCreate(Calendar cal, int hour, int minute, int second) throws SQLException { if (!this.useLegacyDatetimeCode) { return TimeUtil.fastTimeCreate(hour, minute, second, cal); } if (cal == null) { createCalendarIfNeeded(); cal = this.fastDateCal; } return TimeUtil.fastTimeCreate(cal, hour, minute, second); } protected synchronized Timestamp fastTimestampCreate(Calendar cal, int year, int month, int day, int hour, int minute, int seconds, int secondsPart) { if (!this.useLegacyDatetimeCode) { return TimeUtil.fastTimestampCreate(cal.getTimeZone(), year, month, day, hour, minute, seconds, 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 // --------------------------------------------------------------------- /* * [For JDBC-3.0 and older - http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#findColumn(java.lang.String)] * 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 * * [For JDBC-4.0 and newer - http://java.sun.com/javase/6/docs/api/java/sql/ResultSet.html#findColumn(java.lang.String)] * * Maps the given ResultSet column label to its ResultSet column index. * * @param columnLabel * the label for the column specified with the SQL AS clause. If the * SQL AS clause was not specified, then the label is the name of the column * * @return the column index of the given column name */ public synchronized int findColumn(String columnName) throws SQLException { Integer index; if (!this.hasBuiltIndexMapping) { buildIndexMapping(); } index = (Integer) this.columnToIndexCache.get(columnName); if (index != null) { return index.intValue() + 1; } index = (Integer) this.columnLabelToIndex.get(columnName); if (index == null && this.useColumnNamesInFindColumn) { index = (Integer) this.columnNameToIndex.get(columnName); } if (index == null) { index = (Integer) this.fullColumnNameToIndex.get(columnName); } if (index != null) { this.columnToIndexCache.put(columnName, index); 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(); boolean b = true; if (this.rowData.isEmpty()) { b = false; } else { if (this.onInsertRow) { this.onInsertRow = false; } if (this.doingUpdates) { this.doingUpdates = false; } this.rowData.beforeFirst(); this.thisRow = this.rowData.next(); } setRowPositionValidity(); return b; } /** * 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 SQLError.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, Constants.integerValueOf(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", //$NON-NLS-1$ new Object[] {stringVal, new Integer(columnIndex)}), 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[] { Constants.integerValueOf(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[] { Constants.integerValueOf(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!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -