📄 jdbcconnection.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.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.InputStream;import java.io.OutputStream;import java.net.Socket;import java.net.URL;import java.net.URLConnection;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DatabaseMetaData;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.SQLWarning;import java.sql.Statement;import java.util.*; // for Mapimport java.util.Hashtable;import java.util.StringTokenizer;// 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.Connection 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// fredt@users 20020830 - patch 487323 by xclayl@users - better synchronization/** * <!-- start generic documentation --> * A connection (session) with a specific database. Within the context * of a Connection, SQL statements are executed and results * are returned. <p> * * A Connection's database is able to provide information describing * its tables, its supported SQL grammar, its stored procedures, the * capabilities of this connection, and so on. This information is * obtained with the <code>getMetaData</code> method. <p> * * <B>Note:</B> By default the Connection automatically commits * changes after executing each statement. If auto commit has been * disabled, an explicit commit must be done or database changes will * not be saved. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * To get a <code>Connection</code> to an HSQLDB database, the * following code may be used: <p> * * <code class="JavaCodeExample"> * Class.<b>forName</b> (<span class="JavaStringLiteral"> * "org.hsqldb.jdbcDriver"</span> );<br> * Connection c = DriverManager.<b>getConnection</b> * (url,user,password); </code><p> * * For HSQLDB connections, the <B>url</B> must start with <B> * 'jdbc:hsqldb'</B> .<p> * * The {@link Server Server} database <B>url</B> is <B> * 'jdbc:hsqldb:hsql://host[:port]'</B> . <p> * * The {@link WebServer WebServer} database <B>url</B> is <B> * 'jdbc:hsqldb:http://host[:port]'</B> . <p> * * The In-Memory (diskless, in-process) database <B>url</B> is <B> * 'jdbc:hsqldb:.'</B> . <p> * * The Standalone (in-process) database connection <B>url</B> is <B> * 'jdbc:hsqldb:name'</B> . <p> * * <B>'name'</B> is the common prefix of the files that compose the * database, including the <B>path</B> .<p> * * For example: <B>'jdbc:hsqldb:test'</B> connects to a database * named <B>'test'</B> , which is composed of the files <B> * 'test.properties'</B> , <B>'test.data'</B> and <B>'test.script' * </B>, all located in the working directory fixed at the time the * JVM is started. <p> * * Under <em>Windows</em> <sup><font size="-2">TM</font> </sup> , <B> * 'jdbc:hsqldb:c:\databases\test'</B> connects to a database named * <B>'test'</B> , located on drive c: in the directory <B> * 'databases'</B> , composed of the files: <B>'test.properties'</B> * , <B>'test.data'</B> and <B>'test.script'</B> . <p> * * Under most variations of UNIX, <B>'jdbc:hsqldb:/databases/test' * </B> connects to a database named <B>'test'</B> located in the * directory <B>'databases'</B> directly under root, and composed of * the files: <B>'test.properties'</B> , <B>'test.data'</B> and <B> * 'test.script'</B> . <p> * * <B>Some Guidelines:</B> * <OL> * <LI> Both relative and absolute paths are supported.</LI> * <LI> Relative paths can be specified in a platform independent * manner as: <B>'[dir1/dir2/.../dirn/]name'.</B> </LI> * <LI> Specification of absolute paths is operating-system * specific.<br> * Please read your OS file system documentation.</LI> * <LI> Typically, special care must be taken w.r.t. path * specifications containing whitespace, and mixed-case may also be * a concern.<br> * Please read your OS file system documentation.</LI> * </OL> * <B>Note:</B> Previous versions of HSQLDB did not support creating * directories along the path specified in Standalone mode jdbc urls, * in the case that they did not already exist. As of HSQLDB 1.7.0, * directories <i>will</i> be created if they do not already exist * (but not if the HSQLDB Jar is built under JDK 1.1.x). * <p> * * For more information about HSQLDB file structure, please read the * {@link Files Files} section of the documentation. <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 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> * * <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 jdbcDriver * @see jdbcStatement * @see jdbcResultSet * @see jdbcDatabaseMetaData */public class jdbcConnection implements Connection {// ---------------------------- Common Attributes -------------------------- /** * Is this connection closed?<p> * * This attribute is false until the first call to {@link * #close()}. If the close is successful, then this * attribute is set to true and stays true until this connection * is eventually garbage collected. */ private boolean bClosed; /** * The name of this connection's {@link Database Database}, as * known to this connection. <p> * * <B>Note:</B> Network connections know their database name as * the network url of that database, without the protocol * specifier. Connections to in-process database instances know * their database name as the local path specifier for the * database. For in-memory databases, this is always <B>"."</B> */ private String sDatabaseName; /** * Properties for the connection * */ private HsqlProperties connProperties; /** * One of the possible values for this connection's type. <p> * * This value indicates a network <code>Connection</code> to a * {@link org.hsqldb.WebServer WebServer} mode <code>Database</code>, * using http protocol. <p> */ final static int HTTP = 0; /** * One of the possible values for this connection's type. <p> * * This value indicates a <code>Connection</code> to an * in-process (Standalone mode) <code>Database</code>. <p> */ final static int STANDALONE = 1; /** * One of the possible values for this connection's type. <p> * * This value indicates a <code>Connection</code> created inside * the database on behalf of an existing {@link Session Session}, * to be used as the parameter to a SQL function or stored * procedure that needs to execute in the context of the calling * <code>Session</code>. <p> * * */ final static int INTERNAL = 2; /** * One of the possible values for this connection's type. <p> * * This value indicates a network <code>Connection</code> to a * {@link org.hsqldb.Server Server} mode <code>Database</code>, * using native hsqldb protocol. <p> * * */ final static int HSQLDB = 3; /** * The type of this connection: {@link #STANDALONE STANDALONE}, * {@link #HSQLDB HSQLDB}, {@link #HTTP HTTP}, or {@link * #INTERNAL INTERNAL}. <p> */ private int iType;// ----------------- In-process Database Connection Attributes ------------- /** * This connection's in-process {@link Database Database}. <p> * * This attribute is used only for {@link #STANDALONE STANDALONE} * or {@link #INTERNAL INTERNAL} type connections. <p> * * */ Database dDatabase; /** * This connection's corresponding in-process {@link * Session Session}.<p> *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -