📄 jdbcstatement.java
字号:
/* Copyrights and Licenses * * This product includes Hypersonic SQL. * Originally developed by Thomas Mueller and the Hypersonic SQL Group. * * Copyright (c) 1995-2000 by 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. * - All advertising materials mentioning features or use of this software must display the * following acknowledgment: "This product includes Hypersonic SQL." * - Products derived from this software may not be called "Hypersonic SQL" nor may * "Hypersonic SQL" appear in their names without prior written permission of the * Hypersonic SQL Group. * - Redistributions of any form whatsoever must retain the following acknowledgment: "This * product includes Hypersonic SQL." * This software is provided "as is" and any expressed 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 its 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 any 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-2002, 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, including earlier * license statements (above) and comply with all above license conditions. * * 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, including earlier * license statements (above) and comply with all above license conditions. * * 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;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.SQLWarning;// 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// boucherb@users 20020509 - added "throws SQLException" to all methods where// it was missing here but specified in the java.sql.Statement interface,// updated generic documentation to JDK 1.4, and added JDBC3 methods and docs// boucherb@users and fredt@users 20020409/20020505 extensive review and update// of docs and behaviour to comply with previous and latest java.sql specification/** * <!-- start generic documentation --> * The object used for executing a static SQL statement * and returning the results it produces. * <P> * By default, only one <code>ResultSet</code> object per <code>Statement</code> * object can be open at the same time. Therefore, if the reading of one * <code>ResultSet</code> object is interleaved * with the reading of another, each must have been generated by * different <code>Statement</code> objects. All execution methods in the * <code>Statement</code> interface implicitly close a statment's current * <code>ResultSet</code> object if an open one exists.<p> * <!-- end generic documentation--> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b><p> * * <b>JRE 1.1.x Notes:</b> <p> * * In general, JDBC 2 support requires Java 1.2 and above, and JDBC3 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 * <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 in * {@link jdbcResultSet jdbcResultSet}.<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> * * <CODE class="JavaCodeExample"> * jdbcResultSet.FETCH_FORWARD<br> * jdbcResultSet.TYPE_FORWARD_ONLY<br> * jdbcResultSet.TYPE_SCROLL_INSENSITIVE<br> * jdbcResultSet.CONCUR_READ_ONLY<br> * </CODE> <p> * * 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> * * (fredt@users)<br> * (boucherb@users)<p> * * </span> * <!-- end release-specific documentation --> * * @see jdbcConnection#createStatement * @see jdbcResultSet */public class jdbcStatement implements java.sql.Statement { /** * Is escape processing enabled? */ private boolean bEscapeProcessing = true; /** * The connection used to execute this statement. */ private jdbcConnection cConnection; /** * The maximum number of rows to generate when executing this statement. */ private int iMaxRows; /** * The result of executing this statement. */ private jdbcResultSet rSet; /** * The result type obtained by executing this statement. */ private int rsType = jdbcResultSet.TYPE_FORWARD_ONLY; /** * <!-- start generic documentation --> * Executes the given SQL statement, which returns a single * <code>ResultSet</code> object. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * * @param sql an SQL statement to be sent to the database, typically a * static SQL <code>SELECT</code> statement * @return a <code>ResultSet</code> object that contains the data produced * by the given query; never <code>null</code> * @exception SQLException if a database access error occurs or the given * SQL statement produces anything other than a single * <code>ResultSet</code> object */ public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); fetchResult(sql); return rSet; } /** * <!-- start generic documentation --> * Executes the given SQL statement, which may be an <code>INSERT</code>, * <code>UPDATE</code>, or <code>DELETE</code> statement or an * SQL statement that returns nothing, such as an SQL DDL statement. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or * <code>DELETE</code> statement or an SQL statement that returns nothing * @return either the row count for <code>INSERT</code>, <code>UPDATE</code> * or <code>DELETE</code> statements, or <code>0</code> for SQL statements * that return nothing * @exception SQLException if a database access error occurs or the given * SQL statement produces a <code>ResultSet</code> object */ public int executeUpdate(String sql) throws SQLException { checkClosed(); fetchResult(sql); if (rSet == null) { return -1; } return rSet.getUpdateCount(); } /** * <!-- start generic documentation --> * Releases this <code>Statement</code> object's database * and JDBC resources immediately instead of waiting for * this to happen when it is automatically closed. * It is generally good practice to release resources as soon as * you are finished with them to avoid tying up database * resources. * <P> * Calling the method <code>close</code> on a <code>Statement</code> * object that is already closed has no effect. * <P> * <B>Note:</B> A <code>Statement</code> object is automatically closed * when it is garbage collected. When a <code>Statement</code> object is * closed, its current <code>ResultSet</code> object, if one exists, is * also closed. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @exception SQLException if a database access error occurs */ public void close() throws SQLException { if (Trace.TRACE) { Trace.trace(); } closeOldResult(); rSet = null; } //---------------------------------------------------------------------- /** * <!-- start generic documentation --> * Retrieves the maximum number of bytes that can be * returned for character and binary column values in a <code>ResultSet</code> * object produced by this <code>Statement</code> object. * This limit applies only to <code>BINARY</code>, * <code>VARBINARY</code>, <code>LONGVARBINARY</code>, <code>CHAR</code>, * <code>VARCHAR</code>, and <code>LONGVARCHAR</code> * columns. If the limit is exceeded, the excess data is silently * discarded. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</B> <p> * * Up to and including 1.7.1, HSQLDB always returns zero, meaning there * is no limit. <p> * * </span> * <!-- end release-specific documentation --> * * @return the current column size limit for columns storing character and * binary values; zero means there is no limit * @exception SQLException if a database access error occurs * @see #setMaxFieldSize */ public int getMaxFieldSize() throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); return 0; } /** * <!-- start generic documentation --> * Sets the limit for the maximum number of bytes in a <code>ResultSet</code> * column storing character or binary values to * the given number of bytes. This limit applies * only to <code>BINARY</code>, <code>VARBINARY</code>, * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>, and * <code>LONGVARCHAR</code> fields. If the limit is exceeded, the excess data * is silently discarded. For maximum portability, use values * greater than 256. <p> * <!-- emd generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Calls to this method are simply ignored; HSQLDB always stores the * full number of bytes when dealing with any of the field types * mentioned above. These types all have an absolute maximum element upper * bound determined by the Java array index limit * java.lang.Integer.MAX_VALUE. For XXXBINARY types, this translates to * Integer.MAX_VALUE bytes. For XXXCHAR types, this translates to * 2 * Integer.MAX_VALUE bytes (2 bytes / character) * * </span> * <!-- end release-specific documentation --> * * @param max the new column size limit in bytes; zero means there is no limit * @exception SQLException if a database access error occurs * or the condition max >= 0 is not satisfied * @see #getMaxFieldSize */ public void setMaxFieldSize(int max) throws SQLException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -