📄 jdbcresultset.java
字号:
if (x instanceof byte[]) { return (byte[]) x; } if (x instanceof java.lang.String) { return ((String) x).getBytes(); } x = getColumnInType(--columnIndex, Types.BINARY); return (byte[]) x; } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a * <code>java.sql.Date</code> object in the Java programming language.<p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> * @exception SQLException if a database access error occurs */ public java.sql.Date getDate(int columnIndex) throws SQLException { return (java.sql.Date) getColumnInType(columnIndex, Types.DATE); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a <code>java.sql.Time</code> * object in the Java programming language. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> * @exception SQLException if a database access error occurs */ public java.sql.Time getTime(int columnIndex) throws SQLException { return (Time) getColumnInType(columnIndex, Types.TIME); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>java.sql.Timestamp</code> object in the Java programming * language. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> * @exception SQLException if a database access error occurs */ public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException { return (Timestamp) getColumnInType(columnIndex, Types.TIMESTAMP); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a stream of ASCII characters. The value can then be read in chunks * from the stream. This method is particularly * suitable for retrieving large <char>LONGVARCHAR</char> 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 getter method implicitly closes the stream. Also, a * stream may return <code>0</code> when the method * <code>InputStream.available</code> * is called whether there is data available or not. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * The limitation noted above does not apply to HSQLDB.<p> * * Up to and including 1.6.1, getAsciiStream was identical to * getUnicodeStream and both simply returned a byte stream * constructed from the raw {@link #getBytes(int) getBytes} * representation. * * Starting with 1.7.0, this has been updated to comply with the * java.sql specification. * * When the column is of type CHAR and its variations, it requires no * conversion since it is represented internally already as * Java Strings. When the column is not of type CHAR and its variations, * the returned stream is based on a conversion to the * Java <CODE>String</CODE> representation of the value. In either case, * the obtained stream is always equivalent to a stream of the low order * bytes from the value's String representation. <p> * * HSQLDB SQL <CODE>CHAR</CODE> and its variations are all Unicode strings * internally, so the recommended alternatives to this method are * {@link #getString(int) getString}, * {@link #getUnicodeStream(int) getUnicodeStream} (<b>deprecated</b>) * and new to 1.7.0: {@link #getCharacterStream(int) getCharacterStream} * (now prefered over the deprecated getUnicodeStream alternative). <p> * * </span> * <!-- end release-specific documentation --> * * @param columnIndex the first column is 1, the second is 2, ... * @return a Java input stream that delivers the database column value * as a stream of one-byte ASCII characters; * if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> * @exception SQLException if a database access error occurs */ public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException { String s = getString(columnIndex); if (s == null) { return null; } return new AsciiStringInputStream(s); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * as a stream of two-byte Unicode characters. The first byte is * the high byte; the second byte is the low byte. * * The value can then be read in chunks from the * stream. This method is particularly * suitable for retrieving large <code>LONGVARCHAR</code>values. The * JDBC driver will do any necessary conversion from the database * format into Unicode. * * <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 getter method implicitly closes the stream. * Also, a stream may return <code>0</code> when the method * <code>InputStream.available</code> * is called, whether there is data available or not. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * The limitation noted above does not apply to HSQLDB.<p> * * Up to and including 1.6.1, getUnicodeStream (and getAsciiStream) * both simply returned a byte stream constructed from the * raw {@link #getBytes(int) getBytes} representation. * * Starting with 1.7.0, this has been corrected to comply with the * java.sql specification. * * When the column is of type CHAR and its variations, it requires no * conversion since it is represented internally already as * Java Strings. When the column is not of type CHAR and its variations, * the returned stream is based on a conversion to the * Java <CODE>String</CODE> representation of the value. In either case, * the obtained stream is always equivalent to a stream of * bytes from the value's String representation, with high-byte first.<p> * * </span> * <!-- end release-specific documentation --> * * @param columnIndex the first column is 1, the second is 2, ... * @return a Java input stream that delivers the database column value * as a stream of two-byte Unicode characters; * if the value is SQL <code>NULL</code>, the value returned is * <code>null</code> * @exception SQLException if a database access error occurs * @deprecated use <code>getCharacterStream</code> in place of * <code>getUnicodeStream</code> */ public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException { String s = getString(columnIndex); if (s == null) { return null; } return new StringInputStream(s); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a binary stream of * uninterpreted bytes. The value can then be read in chunks from the * stream. This method is particularly * suitable for retrieving large <code>LONGVARBINARY</code> values. * * <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 getter method implicitly closes the stream. Also, a * stream may return <code>0</code> when the method * <code>InputStream.available</code> * is called whether there is data available or not. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnIndex the first column is 1, the second is 2, ... * @return a Java input stream that delivers the database column value * as a stream of uninterpreted bytes; * if the value is SQL <code>NULL</code>, the value returned is * <code>null</code> * @exception SQLException if a database access error occurs */// fredt@users 20020215 - patch 485704 by boucherb@users public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException { byte[] b = getBytes(columnIndex); return wasNull() ? null : new ByteArrayInputStream(b); // or new ByteArrayInputStream(new byte[0]) : ... } //====================================================================== // Methods for accessing results by column name //====================================================================== /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>String</code> in the Java programming language. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnName the SQL name of the column * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> * @exception SQLException if a database access error occurs */ public String getString(String columnName) throws SQLException { return getString(findColumn(columnName)); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>boolean</code> in the Java programming language. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnName the SQL name of the column * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>false</code> * @exception SQLException if a database access error occurs */ public boolean getBoolean(String columnName) throws SQLException { return getBoolean(findColumn(columnName)); } /** * <!-- start generic documentation --> * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>byte</code> in the Java programming language. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param columnName the SQL name of the column * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>0</code> * @exception SQLException if a database access error occurs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -