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

📄 connection.java

📁 java数据库源代码 请看看啊 提点宝贵的意见
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)Connection.java	1.41 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.sql;/** * <P>A connection (session) with a specific * database. SQL statements are executed and results are returned * within the context of a connection. * <P> * A <code>Connection</code> object'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 a <code>Connection</code> object is in * auto-commit mode, which means that it automatically commits changes  * after executing each statement. If auto-commit mode has been * disabled, the method <code>commit</code> must be called explicitly in * order to commit changes; otherwise, database changes will not be saved. * <P> * A new <code>Connection</code> object created using the JDBC 2.1 core API * has an initially empty type map associated with it. A user may enter a * custom mapping for a UDT in this type map. * When a UDT is retrieved from a data source with the * method <code>ResultSet.getObject</code>, the <code>getObject</code> method * will check the connection's type map to see if there is an entry for that * UDT.  If so, the <code>getObject</code> method will map the UDT to the * class indicated.  If there is no entry, the UDT will be mapped using the * standard mapping. * <p> * A user may create a new type map, which is a <code>java.util.Map</code> * object, make an entry in it, and pass it to the <code>java.sql</code> * methods that can perform custom mapping.  In this case, the method * will use the given type map instead of the one associated with * the connection. * <p> * For example, the following code fragment specifies that the SQL * type <code>ATHLETES</code> will be mapped to the class * <code>Athletes</code> in the Java programming language. * The code fragment retrieves the type map for the <code>Connection * </code> object <code>con</code>, inserts the entry into it, and then sets * the type map with the new entry as the connection's type map. * <pre> *      java.util.Map map = con.getTypeMap(); *      map.put("mySchemaName.ATHLETES", Class.forName("Athletes")); *      con.setTypeMap(map); * </pre> * * @see DriverManager#getConnection * @see Statement  * @see ResultSet * @see DatabaseMetaData */public interface Connection {    /**     * Creates a <code>Statement</code> object for sending     * SQL statements to the database.     * SQL statements without parameters are normally     * executed using <code>Statement</code> objects. If the same SQL statement      * is executed many times, it may be more efficient to use a      * <code>PreparedStatement</code> object.     * <P>     * Result sets created using the returned <code>Statement</code>     * object will by default be type <code>TYPE_FORWARD_ONLY</code>     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.     *     * @return a new default <code>Statement</code> object      * @exception SQLException if a database access error occurs     */    Statement createStatement() throws SQLException;    /**     * Creates a <code>PreparedStatement</code> object for sending     * parameterized SQL statements to the database.     * <P>     * A SQL statement with or without IN parameters can be     * pre-compiled 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> This method is optimized for handling     * parametric SQL statements that benefit from precompilation. If     * the driver supports precompilation,     * the method <code>prepareStatement</code> will send     * the statement to the database for precompilation. Some drivers     * may not support precompilation. In this case, the statement may     * not be sent to the database until the <code>PreparedStatement</code>      * object is executed.  This has no direct effect on users; however, it does     * affect which methods throw certain <code>SQLException</code> objects.     * <P>     * Result sets created using the returned <code>PreparedStatement</code>     * object will by default be type <code>TYPE_FORWARD_ONLY</code>     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.     *     * @param sql an SQL statement that may contain one or more '?' IN     * parameter placeholders     * @return a new default <code>PreparedStatement</code> object containing the     * pre-compiled SQL statement      * @exception SQLException if a database access error occurs     */    PreparedStatement prepareStatement(String sql)	throws SQLException;    /**     * Creates a <code>CallableStatement</code> object for calling     * database stored procedures.     * The <code>CallableStatement</code> object provides     * methods for setting up its IN and OUT parameters, and     * methods for executing the call to a stored procedure.     *     * <P><B>Note:</B> This method is optimized for handling stored     * procedure call statements. Some drivers may send the call     * statement to the database when the method <code>prepareCall</code>     * is done; others     * may wait until the <code>CallableStatement</code> object     * is executed. This has no     * direct effect on users; however, it does affect which method     * throws certain SQLExceptions.     * <P>     * Result sets created using the returned <code>CallableStatement</code>     * object will by default be type <code>TYPE_FORWARD_ONLY</code>     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.     *     * @param sql an SQL statement that may contain one or more '?'     * parameter placeholders. Typically this  statement is a JDBC     * function call escape string.     * @return a new default <code>CallableStatement</code> object containing the     * pre-compiled SQL statement      * @exception SQLException if a database access error occurs     */    CallableStatement prepareCall(String sql) throws SQLException;						    /**     * Converts the given SQL statement into the system's native SQL grammar.     * A driver may convert the JDBC SQL grammar into its system's     * native SQL grammar prior to sending it. This method returns the     * native form of the statement that the driver would have sent.     *     * @param sql an SQL statement that may contain one or more '?'     * parameter placeholders     * @return the native form of this statement     * @exception SQLException if a database access error occurs     */    String nativeSQL(String sql) throws SQLException;    /**     * Sets this connection's auto-commit mode to the given state.     * If a connection is in auto-commit mode, then all its SQL     * statements will be executed and committed as individual     * transactions.  Otherwise, its SQL statements are grouped into     * transactions that are terminated by a call to either     * the method <code>commit</code> or the method <code>rollback</code>.     * By default, new connections are in auto-commit     * mode.     * <P>     * The commit occurs when the statement completes or the next     * execute occurs, whichever comes first. In the case of     * statements returning a <code>ResultSet</code> object,      * the statement completes when the last row of the      * <code>ResultSet</code> object has been retrieved or the     * <code>ResultSet</code> object has been closed. In advanced cases, a single     * statement may return multiple results as well as output     * parameter values. In these cases, the commit occurs when all results and     * output parameter values have been retrieved.     * <P>     * <B>NOTE:</B>  If this method is called during a transaction, the     * transaction is committed.     *     * @param autoCommit <code>true</code> to enable auto-commit mode;      *         <code>false</code> to disable it     * @exception SQLException if a database access error occurs     * @see #getAutoCommit     */    void setAutoCommit(boolean autoCommit) throws SQLException;    /**     * Retrieves the current auto-commit mode for this <code>Connection</code>     * object.     *     * @return the current state of this <code>Connection</code> object's      *         auto-commit mode     * @exception SQLException if a database access error occurs     * @see #setAutoCommit      */    boolean getAutoCommit() throws SQLException;    /**     * Makes all changes made since the previous     * commit/rollback permanent and releases any database locks     * currently held by this <code>Connection</code> object.      * This method should be     * used only when auto-commit mode has been disabled.     *     * @exception SQLException if a database access error occurs or this     *            <code>Connection</code> object is in auto-commit mode     * @see #setAutoCommit      */    void commit() throws SQLException;    /**     * Undoes all changes made in the current transaction     * and releases any database locks currently held     * by this <code>Connection</code> object. This method should be      * used only when auto-commit mode has been disabled.     *     * @exception SQLException if a database access error occurs or this     *            <code>Connection</code> object is in auto-commit mode     * @see #setAutoCommit      */    void rollback() throws SQLException;    /**     * Releases this <code>Connection</code> object's database and JDBC resources     * immediately instead of waiting for them to be automatically released.     * <P>     * Calling the method <code>close</code> on a <code>Connection</code>     * object that is already closed is a no-op.     * <P>     * <B>Note:</B> A <code>Connection</code> object is automatically      * closed when it is garbage collected. Certain fatal errors also      * close a <code>Connection</code> object.     *     * @exception SQLException if a database access error occurs     */    void close() throws SQLException;    /**     * Retrieves whether this <code>Connection</code> object has been     * closed.  A connection is closed if the method <code>close</code>     * has been called on it or if certain fatal errors have occurred.     * This method is guaranteed to return <code>true</code> only when     * it is called after the method <code>Connection.close</code> has     * been called.     * <P>     * This method generally cannot be called to determine whether a     * connection to a database is valid or invalid.  A typical client     * can determine that a connection is invalid by catching any     * exceptions that might be thrown when an operation is attempted.     *     * @return <code>true</code> if this <code>Connection</code> object      *         is closed; <code>false</code> if it is still open     * @exception SQLException if a database access error occurs     */    boolean isClosed() throws SQLException;    //======================================================================    // Advanced features:    /**     * Retrieves a <code>DatabaseMetaData</code> object that contains     * metadata about the database to which this     * <code>Connection</code> object represents a connection.     * The metadata includes information about the database's     * tables, its supported SQL grammar, its stored     * procedures, the capabilities of this connection, and so on.     *     * @return a <code>DatabaseMetaData</code> object for this      *         <code>Connection</code> object     * @exception SQLException if a database access error occurs     */    DatabaseMetaData getMetaData() throws SQLException;    /**     * Puts this connection in read-only mode as a hint to the driver to enable      * database optimizations.     *     * <P><B>Note:</B> This method cannot be called during a transaction.     *     * @param readOnly <code>true</code> enables read-only mode;      *        <code>false</code> disables it     * @exception SQLException if a database access error occurs or this     *            method is called during a transaction     */    void setReadOnly(boolean readOnly) throws SQLException;    /**     * Retrieves whether this <code>Connection</code>      * object is in read-only mode.     *     * @return <code>true</code> if this <code>Connection</code> object     *         is read-only; <code>false</code> otherwise     * @exception SQLException if a database access error occurs     */    boolean isReadOnly() throws SQLException;    /**     * Sets the given catalog name in order to select 	

⌨️ 快捷键说明

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