📄 resultset.java
字号:
*/ public java.sql.Blob getBlob(String colName) throws SQLException { return getBlob(findColumn(colName)); } /** * Get the value of a column in the current row as a Java boolean * * @param columnIndex * the first column is 1, the second is 2... * * @return the column value, false for SQL NULL * * @exception SQLException * if a database access error occurs */ public boolean getBoolean(int columnIndex) throws SQLException { checkColumnBounds(columnIndex); // // MySQL 5.0 and newer have an actual BIT type, // so we need to check for that here... // int columnIndexMinusOne = columnIndex - 1; Field field = this.fields[columnIndexMinusOne]; if (field.getMysqlType() == MysqlDefs.FIELD_TYPE_BIT) { return byteArrayToBoolean(columnIndexMinusOne); } this.wasNullFlag = false; int sqlType = field.getSQLType(); switch (sqlType) { case Types.BIT: case Types.BOOLEAN: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: long boolVal = getLong(columnIndex, false); return (boolVal == -1 || boolVal > 0); default: if (this.connection.getPedantic()) { // Table B-6 from JDBC spec switch (sqlType) { case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.CLOB: case Types.BLOB: case Types.ARRAY: case Types.REF: case Types.DATALINK: case Types.STRUCT: case Types.JAVA_OBJECT: throw SQLError.createSQLException("Required type conversion not allowed", SQLError.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST); } } if (sqlType == Types.BINARY || sqlType == Types.VARBINARY || sqlType == Types.LONGVARBINARY || sqlType == Types.BLOB) { return byteArrayToBoolean(columnIndexMinusOne); } if (this.useUsageAdvisor) { issueConversionViaParsingWarning("getBoolean()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { MysqlDefs.FIELD_TYPE_BIT, MysqlDefs.FIELD_TYPE_DOUBLE, MysqlDefs.FIELD_TYPE_TINY, MysqlDefs.FIELD_TYPE_SHORT, MysqlDefs.FIELD_TYPE_LONG, MysqlDefs.FIELD_TYPE_LONGLONG, MysqlDefs.FIELD_TYPE_FLOAT }); } String stringVal = getString(columnIndex); return getBooleanFromString(stringVal, columnIndex); } } private boolean byteArrayToBoolean(int columnIndexMinusOne) { if (this.thisRow[columnIndexMinusOne] == null) { this.wasNullFlag = true; return false; } this.wasNullFlag = false; if (((byte[]) this.thisRow[columnIndexMinusOne]).length == 0) { return false; } byte boolVal = ((byte[]) this.thisRow[columnIndexMinusOne])[0]; return (boolVal == -1 || boolVal > 0); } /** * DOCUMENT ME! * * @param columnName * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SQLException * DOCUMENT ME! */ public boolean getBoolean(String columnName) throws SQLException { return getBoolean(findColumn(columnName)); } private final boolean getBooleanFromString(String stringVal, int columnIndex) throws SQLException { if ((stringVal != null) && (stringVal.length() > 0)) { int c = Character.toLowerCase(stringVal.charAt(0)); return ((c == 't') || (c == 'y') || (c == '1') || stringVal .equals("-1")); } return false; } /** * Get the value of a column in the current row as a Java byte. * * @param columnIndex * the first column is 1, the second is 2,... * * @return the column value; 0 if SQL NULL * * @exception SQLException * if a database access error occurs */ public byte getByte(int columnIndex) throws SQLException { if (!this.isBinaryEncoded) { String stringVal = getString(columnIndex); if (this.wasNullFlag || (stringVal == null)) { return 0; } return getByteFromString(stringVal, columnIndex); } return getNativeByte(columnIndex); } /** * DOCUMENT ME! * * @param columnName * DOCUMENT ME! * * @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(); } // // 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(); try { int decimalIndex = stringVal.indexOf("."); if (decimalIndex != -1) { double valueAsDouble = Double.parseDouble(stringVal); if (this.connection.getJdbcCompliantTruncationForReads()) { 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.getJdbcCompliantTruncationForReads()) { if (valueAsLong < Byte.MIN_VALUE || valueAsLong > Byte.MAX_VALUE) { throwRangeException(String.valueOf(valueAsLong), columnIndex, Types.TINYINT); } } return (byte) valueAsLong; } catch (NumberFormatException NFE) { throw SQLError.createSQLException( 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(); checkColumnBounds(columnIndex); if (this.thisRow[columnIndex - 1] == null) { this.wasNullFlag = true; } else { this.wasNullFlag = false; } 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(), this.connection); } return null; } /** * Optimization to only use one calendar per-session, or calculate it for * each call, depending on user configuration */ private 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) { String asString = getStringForClob(columnIndex); if (asString == null) { return null; } return new StringReader(asString); } 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -