📄 resultset.java
字号:
* @return DOCUMENT ME! * * @throws SQLException * DOCUMENT ME! */ public byte getByte(String columnName) throws SQLException { return getByte(findColumn(columnName)); } private final byte getByteFromString(String stringVal, int columnIndex) throws SQLException { if (stringVal != null && stringVal.length() == 0) { return (byte) convertToZeroWithEmptyCheck(); } try { int decimalIndex = stringVal.indexOf("."); if (decimalIndex != -1) { double valueAsDouble = Double.parseDouble(stringVal); if (this.connection.getJdbcCompliantTruncation()) { if (valueAsDouble < Byte.MIN_VALUE || valueAsDouble > Byte.MAX_VALUE) { throwRangeException(stringVal, columnIndex, Types.TINYINT); } } return (byte) valueAsDouble; } long valueAsLong = Long.parseLong(stringVal); if (this.connection.getJdbcCompliantTruncation()) { if (valueAsLong < Byte.MIN_VALUE || valueAsLong > Byte.MAX_VALUE) { throwRangeException(String.valueOf(valueAsLong), columnIndex, Types.TINYINT); } } return (byte) valueAsLong; } catch (NumberFormatException NFE) { throw new SQLException( Messages.getString("ResultSet.Value____173") + stringVal //$NON-NLS-1$ + Messages .getString("ResultSet.___is_out_of_range_[-127,127]_174"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } } /** * Get the value of a column in the current row as a Java byte array. * * <p> * <b>Be warned</b> If the blob is huge, then you may run out of memory. * </p> * * @param columnIndex * the first column is 1, the second is 2, ... * * @return the column value; if the value is SQL NULL, the result is null * * @exception SQLException * if a database access error occurs */ public byte[] getBytes(int columnIndex) throws SQLException { return getBytes(columnIndex, false); } protected byte[] getBytes(int columnIndex, boolean noConversion) throws SQLException { if (!this.isBinaryEncoded) { checkRowPos(); try { if (this.thisRow[columnIndex - 1] == null) { this.wasNullFlag = true; } else { this.wasNullFlag = false; } } catch (NullPointerException E) { this.wasNullFlag = true; } catch (ArrayIndexOutOfBoundsException aioobEx) { 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.wasNullFlag) { return null; } return (byte[]) this.thisRow[columnIndex - 1]; } 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()); } return null; } /** * Optimization to only use one calendar per-session, or calculate it for * each call, depending on user configuration */ private synchronized Calendar getCalendarInstanceForSessionOrNew() { if (this.connection.getDynamicCalendars()) { return Calendar.getInstance(); } if (this.sessionCalendar == null) { this.sessionCalendar = Calendar.getInstance(); } return this.sessionCalendar; } /** * 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) { String stringVal = getString(columnIndex); if (stringVal != null) { return new StringReader(stringVal); } return null; } 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 = getString(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 new SQLException(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()); } String stringVal = getStringInternal(columnIndex, false); if (stringVal == null) { return null; } return getDateFromString(stringVal, columnIndex); } /** * 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) throws SQLException { int year = 0; int month = 0; int day = 0; try { this.wasNullFlag = false; if (stringVal == null) { this.wasNullFlag = true; return null; } else if (stringVal.equals("0") || stringVal.equals("0000-00-00") || stringVal.equals("0000-00-00 00:00:00") || stringVal.equals("00000000000000") || stringVal.equals("0")) { if (ConnectionProperties.ZERO_DATETIME_BEHAVIOR_CONVERT_TO_NULL .equals(this.connection.getZeroDateTimeBehavior())) { this.wasNullFlag = true; return null; } else if (ConnectionProperties.ZERO_DATETIME_BEHAVIOR_EXCEPTION .equals(this.connection.getZeroDateTimeBehavior())) { throw new SQLException("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(null, 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(null, 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(null, 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(null, 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(null, year + 1900, month, 1); } case 2: { year = Integer.parseInt(stringVal.substring(0, 2)); if (year <= 69) { year = year + 100; } return fastDateCreate(null, year + 1900, 1, 1); } default: throw new SQLException(Messages.getString( "ResultSet.Bad_format_for_Date", new Object[] { stringVal, new Integer(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(null, year, 1, 1); } else if (this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TIME) { return fastDateCreate(null, 1970, 1, 1); // Return EPOCH } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -