📄 jdbcresultset.java
字号:
/* Copyright (c) 1995-2000, The Hypersonic SQL Group.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Hypersonic SQL Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Hypersonic SQL Group.
*
*
* For work added by the HSQL Development Group:
*
* Copyright (c) 2001-2005, The HSQL Development Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the HSQL Development Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hsqldb.jdbc;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
//#ifdef JAVA2
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Ref;
import java.util.Map;
//#endif JAVA2
import org.hsqldb.Column;
import org.hsqldb.HsqlDateTime;
import org.hsqldb.HsqlException;
import org.hsqldb.Record;
import org.hsqldb.Result;
import org.hsqldb.ResultConstants;
import org.hsqldb.Trace;
import org.hsqldb.Types;
import org.hsqldb.lib.AsciiStringInputStream;
import org.hsqldb.lib.StringInputStream;
import org.hsqldb.persist.HsqlProperties;
import org.hsqldb.types.Binary;
import org.hsqldb.types.JavaObject;
// fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping
// JDBC 2 methods can now be called from jdk 1.1.x - see javadoc comments
// SCROLL_INSENSITIVE and FORWARD_ONLY types for ResultSet are now supported
// fredt@users 20020315 - patch 497714 by lakuhns@users - scrollable ResultSet
// all absolute and relative positioning methods defined
// boucherb@users 20020409 - added "throws SQLException" to all methods where
// it was missing here but specified in the java.sql.ResultSet and
// java.sql.ResultSetMetaData interfaces, updated generic documentation to
// JDK 1.4, and added JDBC3 methods and docs
// boucherb@users and fredt@users 20020505 extensive review and update
// of docs and behaviour to comply with java.sql specification
// tony_lai@users 20020820 - patch 595073 - duplicated exception msg
// fredt@users 20030622 - patch 1.7.2 - columns and labels are case sensitive
// boucherb@users 200404xx - javadoc updates
/**
* <!-- start generic documentation -->
* A table of data representing a database result set, which
* is usually generated by executing a statement that queries the database.
*
* <P>A <code>ResultSet</code> object maintains a cursor pointing
* to its current row of data. Initially the cursor is positioned
* before the first row. The <code>next</code> method moves the
* cursor to the next row, and because it returns <code>false</code>
* when there are no more rows in the <code>ResultSet</code> object,
* it can be used in a <code>while</code> loop to iterate through
* the result set.
* <P>
* A default <code>ResultSet</code> object is not updatable and
* has a cursor that moves forward only. Thus, you can
* iterate through it only once and only from the first row to the
* last row. It is possible to
* produce <code>ResultSet</code> objects that are scrollable and/or
* updatable. The following code fragment, in which <code>con</code>
* is a valid <code>Connection</code> object, illustrates how to make
* a result set that is scrollable and insensitive to updates by others,
* and that is updatable. See <code>ResultSet</code> fields for other
* options.
* <PRE>
*
* Statement stmt = con.createStatement(
* ResultSet.TYPE_SCROLL_INSENSITIVE,
* ResultSet.CONCUR_UPDATABLE);
* ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
* // rs will be scrollable, will not show changes made by others,
* // and will be updatable
*
* </PRE>
* The <code>ResultSet</code> interface provides
* <i>getter</i> methods (<code>getBoolean</code>, <code>getLong</code>,
* and so on) for retrieving column values from the current row.
* Values can be retrieved using either the index number of the
* column or the name of the column. In general, using the
* column index will be more efficient. Columns are numbered from 1.
* For maximum portability, result set columns within each row should be
* read in left-to-right order, and each column should be read only once.
*
* <P>For the getter methods, a JDBC driver attempts
* to convert the underlying data to the Java type specified in the
* getter method and returns a suitable Java value. The JDBC specification
* has a table showing the allowable mappings from SQL types to Java types
* that can be used by the <code>ResultSet</code> getter methods.
* <P>
* <P>Column names used as input to getter methods are case
* insensitive. When a getter method is called with
* a column name and several columns have the same name,
* the value of the first matching column will be returned.
* The column name option is
* designed to be used when column names are used in the SQL
* query that generated the result set.
* For columns that are NOT explicitly named in the query, it
* is best to use column numbers. If column names are used, there is
* no way for the programmer to guarantee that they actually refer to
* the intended columns.
* <P>
* A set of updater methods were added to this interface
* in the JDBC 2.0 API (Java<sup><font size=-2>TM</font></sup> 2 SDK,
* Standard Edition, version 1.2). The comments regarding parameters
* to the getter methods also apply to parameters to the
* updater methods.
* <P>
* The updater methods may be used in two ways:
* <ol>
* <LI>to update a column value in the current row. In a scrollable
* <code>ResultSet</code> object, the cursor can be moved backwards
* and forwards, to an absolute position, or to a position
* relative to the current row.
* The following code fragment updates the <code>NAME</code> column
* in the fifth row of the <code>ResultSet</code> object
* <code>rs</code> and then uses the method <code>updateRow</code>
* to update the data source table from which <code>rs</code> was
* derived.
* <PRE>
*
* rs.absolute(5); // moves the cursor to the fifth row of rs
* rs.updateString("NAME", "AINSWORTH"); // updates the
* // <code>NAME</code> column of row 5 to be <code>AINSWORTH</code>
* rs.updateRow(); // updates the row in the data source
*
* </PRE>
* <LI>to insert column values into the insert row. An updatable
* <code>ResultSet</code> object has a special row associated with
* it that serves as a staging area for building a row to be inserted.
* The following code fragment moves the cursor to the insert row, builds
* a three-column row, and inserts it into <code>rs</code> and into
* the data source table using the method <code>insertRow</code>.
* <PRE>
*
* rs.moveToInsertRow(); // moves cursor to the insert row
* rs.updateString(1, "AINSWORTH"); // updates the
* // first column of the insert row to be <code>AINSWORTH</code>
* rs.updateInt(2,35); // updates the second column to be <code>35</code>
* rs.updateBoolean(3, true); // updates the third row to <code>true</code>
* rs.insertRow();
* rs.moveToCurrentRow();
*
* </PRE>
* </ol>
* <P>A <code>ResultSet</code> object is automatically closed when the
* <code>Statement</code> object that
* generated it is closed, re-executed, or used
* to retrieve the next result from a sequence of multiple results.
*
* <P>The number, types and properties of a <code>ResultSet</code>
* object's columns are provided by the <code>ResulSetMetaData</code>
* object returned by the <code>ResultSet.getMetaData</code> method. <p>
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* A <code>ResultSet</code> object generated by HSQLDB is by default of
* <code>ResultSet.TYPE_FORWARD_ONLY</code> (as is standard JDBC behavior)
* and does not allow the use of absolute and relative positioning
* methods. However, since 1.7.0, if a statement is created
* with:<p>
*
* <pre class="JavaCodeExample">
* Statement stmt = conn.<b>createStatement</b>(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
* </pre>
*
* then the <code>ResultSet</code> objects it produces support
* using all of the absolute and relative positioning methods of JDBC2
* to set the position of the current row, for example:<p>
*
* <pre class="JavaCodeExample">
* rs.<b>absolute</b>(<span class="JavaNumericLiteral">5</span>);
* String fifthRowValue = rs.<b>getString</b>(<span class="JavaNumericLiteral">1</span>);
* rs.<b>relative</b>(<span class="JavaNumericLiteral">4</span>);
* String ninthRowValue = rs.<b>getString</b>(<span class="JavaNumericLiteral">1</span>);
* </pre>
*
* Note: An HSQLDB <code>ResultSet</code> object persists, even after its
* connection is closed. This is regardless of the operational mode of
* the {@link Database Database} from which it came. That is, they
* persist whether originating from a <code>Server</code>,
* <code>WebServer</code> or in-process mode <code>Database.</code>
* <p>
*
* Including HSQLDB 1.7.2, there is no support for any of the methods
* introduced in JDBC 2 relating to updateable result sets. These methods
* include all updateXXX methods, as well as the {@link #insertRow},
* {@link #updateRow}, {@link #deleteRow}, {@link #moveToInsertRow} (and so on)
* methods; invoking any such method throws an <code>SQLException</code>
* stating that the operation is not supported.
*
* <b>JRE 1.1.x Notes:</b> <p>
*
* In general, JDBC 2 support requires Java 1.2 and above, and JDBC 3 requires
* Java 1.4 and above. In HSQLDB, support for methods introduced in different
* versions of JDBC depends on the JDK version used for compiling and building
* HSQLDB.<p>
*
* Since 1.7.0, it is possible to build the product so that
* all JDBC 2 methods can be called while executing under the version 1.1.x
* <em>Java Runtime Environment</em><sup><font size="-2">TM</font></sup>.
* However, some of these method calls require <code>int</code> values that
* are defined only in the JDBC 2 or greater version of the
* <a href="http://java.sun.com/j2se/1.4/docs/api/java/sql/ResultSet.html">
* <code>ResultSet</code></a> interface. For this reason, when the
* product is compiled under JDK 1.1.x, these values are defined here, in this
* class. <p>
*
* In a JRE 1.1.x environment, calling JDBC 2 methods that take or return the
* JDBC2-only <code>ResultSet</code> values can be achieved by referring
* to them in parameter specifications and return value comparisons,
* respectively, as follows: <p>
*
* <pre class="JavaCodeExample">
* jdbcResultSet.FETCH_FORWARD
* jdbcResultSet.TYPE_FORWARD_ONLY
* jdbcResultSet.TYPE_SCROLL_INSENSITIVE
* jdbcResultSet.CONCUR_READ_ONLY
* // etc.
* </pre>
*
* However, please note that code written in such a manner will not be
* compatible for use with other JDBC 2 drivers, since they expect and use
* <code>ResultSet</code>, rather than <code>jdbcResultSet</code>. Also
* note, this feature is offered solely as a convenience to developers
* who must work under JDK 1.1.x due to operating constraints, yet wish to
* use some of the more advanced features available under the JDBC 2
* specification.<p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -