⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbcpreparedstatement.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* 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.io.IOException;import java.io.InputStream;import java.io.Reader;import java.math.BigDecimal;import java.sql.*;     // for Array, Blob, Clob, Refimport java.sql.CallableStatement;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Time;import java.sql.Timestamp;import java.sql.Types;import java.util.*;    // for Mapimport java.util.Calendar;import java.util.Vector;import org.hsqldb.lib.HsqlDateTime;// 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// boucherb@users 20020509 - added "throws SQLException" to all methods where// it was missing here but specified in the java.sql.PreparedStatement and// java.sqlCallableStatement interfaces, 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 Release-specific documentation --> * Implements both the <CODE>java.sql.PreparedStatement</CODE> and * <CODE>java.sql.CallableStatement</CODE> interfaces. <p> * * <span class="ReleaseSpecificDocumentation"> * In short: <p> * * <UL> * <LI>A <CODE>PreparedStatement</CODE> is used to precompile and * execute SQL statements, possibly using parameters.</LI> * <LI>A <CODE>CallableStatement</CODE> is used to execute SQL * stored procedures.</LI> * </UL> * <p> * * The following is composed of three sections: * <OL> * <LI>The generic overview for <CODE>PreparedStatement</CODE>.</LI> * <LI>The generic overview for <CODE>CallableStatement</CODE>.</LI> * <LI>A discussion of some HSQLDB-specific concerns.</LI> * </OL> * </span> <p> * <!-- end Release-specific documentation --> * * <!-- start generic PreparedStatement documentation --> * <B>From <CODE>PreparedStatement</CODE>:</B><p> * * An object that represents a precompiled SQL statement. <p> * * A SQL statement is precompiled and stored in a * <code>PreparedStatement</code> object. This object can then be used to * efficiently execute this statement multiple times. * * <P><B>Note:</B> The setter methods (<code>setShort</code>, * <code>setString</code>, and so on) for setting IN parameter values * must specify types that are compatible with the defined SQL type of * the input parameter. For instance, if the IN parameter has SQL type * <code>INTEGER</code>, then the method <code>setInt</code> should be * used. <p> * * If arbitrary parameter type conversions are required, the method * <code>setObject</code> should be used with a target SQL type. * <P> * In the following example of setting a parameter, <code>con</code> * represents an active connection: * <PRE> * PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES *                               SET SALARY = ? WHERE ID = ?"); * pstmt.setBigDecimal(1, 153833.00) * pstmt.setInt(2, 110592) * </PRE> <p> * <!-- end generic PreparedStatement documentation --> * * <!-- start generic CallableStatement documentation --> * <B>From <CODE>CallableStatement</CODE>:</B><p> * * The interface used to execute SQL stored procedures. <p> * * The JDBC API provides a stored procedure SQL escape syntax that * allows stored procedures to be called in a standard way for all * RDBMSs. This escape syntax has one form that includes a result * parameter and one that does not. If used, the result parameter must * be registered as an OUT parameter. The other parameters * can be used for input, output or both. Parameters are referred to * sequentially, by number, with the first parameter being 1. * <PRE> * {?= call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]} * {call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]} * </PRE> * <P> * IN parameter values are set using the <code>set</code> methods * inherited from <a href= * "http://java.sun.com/j2se/1.4/docs/api/java/sql/PreparedStatement.html" * ><CODE>PreparedStatement</CODE></a>.  The type of all * OUT parameters must be registered prior to executing the stored * procedure; their values are retrieved after execution via the * <code>get</code> methods provided here. * <P> * A <code>CallableStatement</code> can return one <a href= * "http://java.sun.com/j2se/1.4/docs/api/java/sql/ResultSet.html"> * <CODE>ResultSet</CODE></a> object or  multiple <code>ResultSet</code> * objects.  Multiple <code>ResultSet</code> objects are handled using * operations inherited from <a href=" * http://java.sun.com/j2se/1.4/docs/api/java/sql/Statement.html"> * <CODE>Statement</CODE></a>. * <P> * For maximum portability, a call's <code>ResultSet</code> objects and * update counts should be processed prior to getting the values of * output parameters. <p> * <!-- end generic CallableStatement documentation --> * * <!-- start Release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <B>HSQLDB-Specific Information:</B> <p> * * Up to and including HSQLDB 1.7.0, support for stored procedures is * not provided in the conventional fashion, if there is such a thing. <p> * * Stored procedures are typically supported in ways that vary greatly * from one DBMS implementation to the next.  So, it is almost * guaranteed that the code for a stored procedure written under a * specific DBMS product will not work without modification in the * context of another vendor's product or even across a single vendor's * product lines.  Moving stored procedures from one DBMS product line to * another almost invariably involves complex porting issues and often * may not be possible at all.  Be warned. <p> * * HSQLDB stored procedures map directly onto the methods of compiled * Java classes found on the classpath of the engine.  This is done in * a non-standard but fairly efficient way by issuing a class grant (and * possibly method aliases) of the form: <p> * * <PRE> * GRANT ALL ON CLASS "package.class" TO [user_name | PUBLIC] * CREATE ALIAS call_name FOR ""package.class.method" -- optional * </PRE> * * This has the effect of allowing the specified user(s) to access all * of the public static methods of the specified class in either the role * of SQL functions or stored procedures.  For example: * * <PRE> * GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC; * CONNECT anyuser PASSWORD *****; * SELECT "java.lang.Math.abs"(column_1) FROM table_1; * CREATE ALIAS abs FOR "java.lang.Math.abs" * CALL abs(-5); * </PRE> * * However, no support for more advanced features is provided at this * time. That is, the <CODE>CallableStatement</CODE> methods for working * with <CODE>OUT</CODE> parameters are not yet supported because--at a * lower level--in all cases the HSQLDB database engine notes and returns * <i>only</i> the result set or update count generated by executing a * statement. <p> * * So, while some systems may <I>require</I> working with <CODE>OUT</CODE> * parameters when calling stored procedures, this is currently never * the case for HSQLDB; attempting to do so will always result in * throwing a <CODE>SQLException</CODE>, stating that the function * is not supported. <p> * * Please also note that the HSQLDB stored procedure mechanism is essentially * a wrap of the HSQLDB SQL function mechanism, simply allowing Java methods to * be called outside of an <CODE>INSERT</CODE>, <CODE>UPDATE</CODE>, * <CODE>DELETE</CODE> or <CODE>SELECT</CODE> statement context. * That is, issuing any <CODE>CALL</CODE> statement has virtually the * the same effect as: * * <PRE> * CREATE TABLE DUAL (dummy VARCHAR); * INSERT INTO DUAL VALUES NULL; * SELECT "package.class.method"(paramter_list) FROM DUAL; * </PRE> * * In other words, HSQLDB does not yet support stored procedures that * return true result sets.  Instead, Java methods invoked as * HSQLDB stored procedures <I>must</I> return a single value that is * compatible with a supported HSQLDB SQL type.  Furthermore, the * return value is always wrapped in a result object with one column * and one row, before it is handed off to client code.<p> * * This behviour will definitely change in 1.7.1 and above, in that HSQLDB * will also allow stored procedures to return a single, true result set. * However, it is uncertain at this time when/if support for <code>OUT</code> * parameters will be introduced. <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#prepareStatement * @see jdbcConnection#prepareCall * @see jdbcResultSet */public class jdbcPreparedStatement extends org.hsqldb.jdbcStatementimplements java.sql.PreparedStatement, java.sql.CallableStatement {    /**     * The SQL query this object represents.     */    private String sSql;    /**     * The list of values used to replace the parameters of the SQL statement     * this object represents     */    private Vector vParameter;// fredt@users 20020215 - patch 517028 by peterhudson@users - method defined// fredt@users 20020215 - patch 517028 by peterhudson@users - method defined//// changes by fredt// SimpleDateFormat objects moved out of methods to improve performance// this is safe because only one thread at a time should access a// PreparedStatement object until it has finished executing the statement// fredt@users 20020215 - patch 517028 by peterhudson@users - method defined// minor changes by fredt

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -