📄 resultsetimpl.java
字号:
int columnIndexMinusOne = columnIndex - 1; if (this.thisRow.isNull(columnIndexMinusOne)) { this.wasNullFlag = true; } else { this.wasNullFlag = false; } if (this.wasNullFlag) { return null; } return this.thisRow.getColumnValue(columnIndexMinusOne); } return getNativeBytes(columnIndex, noConversion); } /** * DOCUMENT ME! * * @param columnName * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SQLException * DOCUMENT ME! */ public byte[] getBytes(String columnName) throws SQLException { return getBytes(findColumn(columnName)); } private final byte[] getBytesFromString(String stringVal, int columnIndex) throws SQLException { if (stringVal != null) { return StringUtils.getBytes(stringVal, this.connection .getEncoding(), this.connection .getServerCharacterEncoding(), this.connection .parserKnowsUnicode(), this.connection); } return null; } /** * Optimization to only use one calendar per-session, or calculate it for * each call, depending on user configuration */ protected Calendar getCalendarInstanceForSessionOrNew() { if (this.connection != null) { return this.connection.getCalendarInstanceForSessionOrNew(); } else { // punt, no connection around return new GregorianCalendar(); } } /** * JDBC 2.0 * * <p> * Get the value of a column in the current row as a java.io.Reader. * </p> * * @param columnIndex * the column to get the value from * * @return the value in the column as a java.io.Reader. * * @throws SQLException * if an error occurs */ public java.io.Reader getCharacterStream(int columnIndex) throws SQLException { 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.getReader(columnIndexMinusOne); } return getNativeCharacterStream(columnIndex); } /** * JDBC 2.0 * * <p> * Get the value of a column in the current row as a java.io.Reader. * </p> * * @param columnName * the column name to retrieve the value from * * @return the value as a java.io.Reader * * @throws SQLException * if an error occurs */ public java.io.Reader getCharacterStream(String columnName) throws SQLException { return getCharacterStream(findColumn(columnName)); } private final java.io.Reader getCharacterStreamFromString(String stringVal, int columnIndex) throws SQLException { if (stringVal != null) { return new StringReader(stringVal); } return null; } /** * JDBC 2.0 Get a CLOB column. * * @param i * the first column is 1, the second is 2, ... * * @return an object representing a CLOB * * @throws SQLException * if an error occurs */ public java.sql.Clob getClob(int i) throws SQLException { if (!this.isBinaryEncoded) { String asString = getStringForClob(i); if (asString == null) { return null; } return new com.mysql.jdbc.Clob(asString); } return getNativeClob(i); } /** * JDBC 2.0 Get a CLOB column. * * @param colName * the column name * * @return an object representing a CLOB * * @throws SQLException * if an error occurs */ public java.sql.Clob getClob(String colName) throws SQLException { return getClob(findColumn(colName)); } private final java.sql.Clob getClobFromString(String stringVal, int columnIndex) throws SQLException { return new com.mysql.jdbc.Clob(stringVal); } /** * JDBC 2.0 Return the concurrency of this result set. The concurrency used * is determined by the statement that created the result set. * * @return the concurrency type, CONCUR_READ_ONLY, etc. * * @throws SQLException * if a database-access error occurs */ public int getConcurrency() throws SQLException { return (CONCUR_READ_ONLY); } /** * Get the name of the SQL cursor used by this ResultSet * * <p> * In SQL, a result table is retrieved though a cursor that is named. The * current row of a result can be updated or deleted using a positioned * update/delete statement that references the cursor name. * </p> * * <p> * JDBC supports this SQL feature by providing the name of the SQL cursor * used by a ResultSet. The current row of a ResulSet is also the current * row of this SQL cursor. * </p> * * <p> * <B>Note:</B> If positioned update is not supported, a SQLException is * thrown. * </p> * * @return the ResultSet's SQL cursor name. * * @exception SQLException * if a database access error occurs */ public String getCursorName() throws SQLException { throw SQLError.createSQLException(Messages .getString("ResultSet.Positioned_Update_not_supported"), SQLError.SQL_STATE_DRIVER_NOT_CAPABLE); //$NON-NLS-1$ } /** * Get the value of a column in the current row as a java.sql.Date object * * @param columnIndex * the first column is 1, the second is 2... * * @return the column value; null if SQL NULL * * @exception java.sql.SQLException * if a database access error occurs */ public java.sql.Date getDate(int columnIndex) throws java.sql.SQLException { return getDate(columnIndex, null); } /** * JDBC 2.0 Get the value of a column in the current row as a java.sql.Date * object. Use the calendar to construct an appropriate millisecond value * for the Date, if the underlying database doesn't store timezone * information. * * @param columnIndex * the first column is 1, the second is 2, ... * @param cal * the calendar to use in constructing the date * * @return the column value; if the value is SQL NULL, the result is null * * @exception SQLException * if a database-access error occurs. */ public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { if (this.isBinaryEncoded) { return getNativeDate(columnIndex, (cal != null) ? cal.getTimeZone() : this.getDefaultTimeZone()); } if (!this.useFastDateParsing) { String stringVal = getStringInternal(columnIndex, false); if (stringVal == null) { return null; } return getDateFromString(stringVal, columnIndex, cal); } checkColumnBounds(columnIndex); int columnIndexMinusOne = columnIndex - 1; if (this.thisRow.isNull(columnIndexMinusOne)) { this.wasNullFlag = true; return null; } this.wasNullFlag = false; return this.thisRow.getDateFast(columnIndexMinusOne, this.connection, this, cal); } /** * DOCUMENT ME! * * @param columnName * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException * DOCUMENT ME! */ public java.sql.Date getDate(String columnName) throws java.sql.SQLException { return getDate(findColumn(columnName)); } /** * Get the value of a column in the current row as a java.sql.Date object. * Use the calendar to construct an appropriate millisecond value for the * Date, if the underlying database doesn't store timezone information. * * @param columnName * is the SQL name of the column * @param cal * the calendar to use in constructing the date * * @return the column value; if the value is SQL NULL, the result is null * * @exception SQLException * if a database-access error occurs. */ public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { return getDate(findColumn(columnName), cal); } private final java.sql.Date getDateFromString(String stringVal, int columnIndex, Calendar targetCalendar) throws SQLException { int year = 0; int month = 0; int day = 0; try { this.wasNullFlag = false; if (stringVal == null) { this.wasNullFlag = true; return null; } // // 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 // stringVal = stringVal.trim(); if (stringVal.equals("0") || stringVal.equals("0000-00-00") || stringVal.equals("0000-00-00 00:00:00") || stringVal.equals("00000000000000") || stringVal.equals("0")) { if (ConnectionPropertiesImpl.ZERO_DATETIME_BEHAVIOR_CONVERT_TO_NULL .equals(this.connection.getZeroDateTimeBehavior())) { this.wasNullFlag = true; return null; } else if (ConnectionPropertiesImpl.ZERO_DATETIME_BEHAVIOR_EXCEPTION .equals(this.connection.getZeroDateTimeBehavior())) { throw SQLError.createSQLException("Value '" + stringVal + "' can not be represented as java.sql.Date", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } // We're left with the case of 'round' to a date Java _can_ // represent, which is '0001-01-01'. return fastDateCreate(targetCalendar, 1, 1, 1); } else if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP) { // Convert from TIMESTAMP switch (stringVal.length()) { case 21: case 19: { // java.sql.Timestamp format year = Integer.parseInt(stringVal.substring(0, 4)); month = Integer.parseInt(stringVal.substring(5, 7)); day = Integer.parseInt(stringVal.substring(8, 10)); return fastDateCreate(targetCalendar, year, month, day); } case 14: case 8: { year = Integer.parseInt(stringVal.substring(0, 4)); month = Integer.parseInt(stringVal.substring(4, 6)); day = Integer.parseInt(stringVal.substring(6, 8)); return fastDateCreate(targetCalendar, year, month, day); } case 12: case 10: case 6: { year = Integer.parseInt(stringVal.substring(0, 2)); if (year <= 69) { year = year + 100; } month = Integer.parseInt(stringVal.substring(2, 4)); day = Integer.parseInt(stringVal.substring(4, 6)); return fastDateCreate(targetCalendar, year + 1900, month, day); } case 4: { year = Integer.parseInt(stringVal.substring(0, 4)); if (year <= 69) { year = year + 100; } month = Integer.parseInt(stringVal.substring(2, 4)); return fastDateCreate(targetCalendar, year + 1900, month, 1); } case 2: { year = Integer.parseInt(stringVal.substring(0, 2)); if (year <= 69) { year = year + 100; } return fastDateCreate(targetCalendar, year + 1900, 1, 1); } default: throw SQLError.createSQLException(Messages.getString( "ResultSet.Bad_format_for_Date", new Object[] { stringVal, Constants.integerValueOf(columnIndex) }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } /* endswitch */ } else if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR) { if (stringVal.length() == 2 || stringVal.length() == 1) { year = Integer.parseInt(stringVal); if (year <= 69) { year = year + 100; } year += 1900; } else { year = Integer.parseInt(stringVal.substring(0, 4)); } return fastDateCreate(targetCalendar, year, 1, 1); } else if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TIME) { return fastDateCreate(targetCalendar, 1970, 1, 1); // Return EPOCH } else { if (stringVal.length() < 10) { if (stringVal.length() == 8) { return fastDateCreate(targetCalendar, 1970, 1, 1); // Return EPOCH for TIME } throw SQLError.createSQLException(Messages.getString( "ResultSet.Bad_format_for_Date", new Object[] { stringVal, Constants.integerValueOf(columnIndex) }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (stringVal.length() != 18) { year = Integer.parseInt(stringVal.substring(0, 4)); month = Integer.parseInt(stringVal.substring(5, 7)); day = Integer.parseInt(stringVal.substring(8, 10)); } else { // JDK-1.3 timestamp format, not real easy to parse positionally :p StringTokenizer st = new StringTokenizer(stringVal, "- "); year = Integer.parseInt(st.nextToken()); month = Integer.parseInt(st.nextToken()); day = Integer.parseInt(st.nextToken()); } } return fastDateCreate(targetCalendar, year, month, day); } catch (SQLException sqlEx) { throw
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -