Path: blob/master/src/java.sql/share/classes/java/sql/Connection.java
41153 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627import java.util.Properties;28import java.util.concurrent.Executor;2930/**31* <P>A connection (session) with a specific32* database. SQL statements are executed and results are returned33* within the context of a connection.34* <P>35* A {@code Connection} object's database is able to provide information36* describing its tables, its supported SQL grammar, its stored37* procedures, the capabilities of this connection, and so on. This38* information is obtained with the {@code getMetaData} method.39*40* <P><B>Note:</B> When configuring a {@code Connection}, JDBC applications41* should use the appropriate {@code Connection} method such as42* {@code setAutoCommit} or {@code setTransactionIsolation}.43* Applications should not invoke SQL commands directly to change the connection's44* configuration when there is a JDBC method available. By default a {@code Connection} object is in45* auto-commit mode, which means that it automatically commits changes46* after executing each statement. If auto-commit mode has been47* disabled, the method {@code commit} must be called explicitly in48* order to commit changes; otherwise, database changes will not be saved.49* <P>50* A new {@code Connection} object created using the JDBC 2.1 core API51* has an initially empty type map associated with it. A user may enter a52* custom mapping for a UDT in this type map.53* When a UDT is retrieved from a data source with the54* method {@code ResultSet.getObject}, the {@code getObject} method55* will check the connection's type map to see if there is an entry for that56* UDT. If so, the {@code getObject} method will map the UDT to the57* class indicated. If there is no entry, the UDT will be mapped using the58* standard mapping.59* <p>60* A user may create a new type map, which is a {@code java.util.Map}61* object, make an entry in it, and pass it to the {@code java.sql}62* methods that can perform custom mapping. In this case, the method63* will use the given type map instead of the one associated with64* the connection.65* <p>66* For example, the following code fragment specifies that the SQL67* type {@code ATHLETES} will be mapped to the class68* {@code Athletes} in the Java programming language.69* The code fragment retrieves the type map for the {@code Connection70* } object {@code con}, inserts the entry into it, and then sets71* the type map with the new entry as the connection's type map.72* <pre>73* java.util.Map map = con.getTypeMap();74* map.put("mySchemaName.ATHLETES", Class.forName("Athletes"));75* con.setTypeMap(map);76* </pre>77*78* @see DriverManager#getConnection79* @see Statement80* @see ResultSet81* @see DatabaseMetaData82* @since 1.183*/84public interface Connection extends Wrapper, AutoCloseable {8586/**87* Creates a {@code Statement} object for sending88* SQL statements to the database.89* SQL statements without parameters are normally90* executed using {@code Statement} objects. If the same SQL statement91* is executed many times, it may be more efficient to use a92* {@code PreparedStatement} object.93* <P>94* Result sets created using the returned {@code Statement}95* object will by default be type {@code TYPE_FORWARD_ONLY}96* and have a concurrency level of {@code CONCUR_READ_ONLY}.97* The holdability of the created result sets can be determined by98* calling {@link #getHoldability}.99*100* @return a new default {@code Statement} object101* @throws SQLException if a database access error occurs102* or this method is called on a closed connection103*/104Statement createStatement() throws SQLException;105106/**107* Creates a {@code PreparedStatement} object for sending108* parameterized SQL statements to the database.109* <P>110* A SQL statement with or without IN parameters can be111* pre-compiled and stored in a {@code PreparedStatement} object. This112* object can then be used to efficiently execute this statement113* multiple times.114*115* <P><B>Note:</B> This method is optimized for handling116* parametric SQL statements that benefit from precompilation. If117* the driver supports precompilation,118* the method {@code prepareStatement} will send119* the statement to the database for precompilation. Some drivers120* may not support precompilation. In this case, the statement may121* not be sent to the database until the {@code PreparedStatement}122* object is executed. This has no direct effect on users; however, it does123* affect which methods throw certain {@code SQLException} objects.124* <P>125* Result sets created using the returned {@code PreparedStatement}126* object will by default be type {@code TYPE_FORWARD_ONLY}127* and have a concurrency level of {@code CONCUR_READ_ONLY}.128* The holdability of the created result sets can be determined by129* calling {@link #getHoldability}.130*131* @param sql an SQL statement that may contain one or more '?' IN132* parameter placeholders133* @return a new default {@code PreparedStatement} object containing the134* pre-compiled SQL statement135* @throws SQLException if a database access error occurs136* or this method is called on a closed connection137*/138PreparedStatement prepareStatement(String sql)139throws SQLException;140141/**142* Creates a {@code CallableStatement} object for calling143* database stored procedures.144* The {@code CallableStatement} object provides145* methods for setting up its IN and OUT parameters, and146* methods for executing the call to a stored procedure.147*148* <P><B>Note:</B> This method is optimized for handling stored149* procedure call statements. Some drivers may send the call150* statement to the database when the method {@code prepareCall}151* is done; others152* may wait until the {@code CallableStatement} object153* is executed. This has no154* direct effect on users; however, it does affect which method155* throws certain SQLExceptions.156* <P>157* Result sets created using the returned {@code CallableStatement}158* object will by default be type {@code TYPE_FORWARD_ONLY}159* and have a concurrency level of {@code CONCUR_READ_ONLY}.160* The holdability of the created result sets can be determined by161* calling {@link #getHoldability}.162*163* @param sql an SQL statement that may contain one or more '?'164* parameter placeholders. Typically this statement is specified using JDBC165* call escape syntax.166* @return a new default {@code CallableStatement} object containing the167* pre-compiled SQL statement168* @throws SQLException if a database access error occurs169* or this method is called on a closed connection170*/171CallableStatement prepareCall(String sql) throws SQLException;172173/**174* Converts the given SQL statement into the system's native SQL grammar.175* A driver may convert the JDBC SQL grammar into its system's176* native SQL grammar prior to sending it. This method returns the177* native form of the statement that the driver would have sent.178*179* @param sql an SQL statement that may contain one or more '?'180* parameter placeholders181* @return the native form of this statement182* @throws SQLException if a database access error occurs183* or this method is called on a closed connection184*/185String nativeSQL(String sql) throws SQLException;186187/**188* Sets this connection's auto-commit mode to the given state.189* If a connection is in auto-commit mode, then all its SQL190* statements will be executed and committed as individual191* transactions. Otherwise, its SQL statements are grouped into192* transactions that are terminated by a call to either193* the method {@code commit} or the method {@code rollback}.194* By default, new connections are in auto-commit195* mode.196* <P>197* The commit occurs when the statement completes. The time when the statement198* completes depends on the type of SQL Statement:199* <ul>200* <li>For DML statements, such as Insert, Update or Delete, and DDL statements,201* the statement is complete as soon as it has finished executing.202* <li>For Select statements, the statement is complete when the associated result203* set is closed.204* <li>For {@code CallableStatement} objects or for statements that return205* multiple results, the statement is complete206* when all of the associated result sets have been closed, and all update207* counts and output parameters have been retrieved.208*</ul>209* <P>210* <B>NOTE:</B> If this method is called during a transaction and the211* auto-commit mode is changed, the transaction is committed. If212* {@code setAutoCommit} is called and the auto-commit mode is213* not changed, the call is a no-op.214*215* @param autoCommit {@code true} to enable auto-commit mode;216* {@code false} to disable it217* @throws SQLException if a database access error occurs,218* setAutoCommit(true) is called while participating in a distributed transaction,219* or this method is called on a closed connection220* @see #getAutoCommit221*/222void setAutoCommit(boolean autoCommit) throws SQLException;223224/**225* Retrieves the current auto-commit mode for this {@code Connection}226* object.227*228* @return the current state of this {@code Connection} object's229* auto-commit mode230* @throws SQLException if a database access error occurs231* or this method is called on a closed connection232* @see #setAutoCommit233*/234boolean getAutoCommit() throws SQLException;235236/**237* Makes all changes made since the previous238* commit/rollback permanent and releases any database locks239* currently held by this {@code Connection} object.240* This method should be241* used only when auto-commit mode has been disabled.242*243* @throws SQLException if a database access error occurs,244* this method is called while participating in a distributed transaction,245* if this method is called on a closed connection or this246* {@code Connection} object is in auto-commit mode247* @see #setAutoCommit248*/249void commit() throws SQLException;250251/**252* Undoes all changes made in the current transaction253* and releases any database locks currently held254* by this {@code Connection} object. This method should be255* used only when auto-commit mode has been disabled.256*257* @throws SQLException if a database access error occurs,258* this method is called while participating in a distributed transaction,259* this method is called on a closed connection or this260* {@code Connection} object is in auto-commit mode261* @see #setAutoCommit262*/263void rollback() throws SQLException;264265/**266* Releases this {@code Connection} object's database and JDBC resources267* immediately instead of waiting for them to be automatically released.268* <P>269* Calling the method {@code close} on a {@code Connection}270* object that is already closed is a no-op.271* <P>272* It is <b>strongly recommended</b> that an application explicitly273* commits or rolls back an active transaction prior to calling the274* {@code close} method. If the {@code close} method is called275* and there is an active transaction, the results are implementation-defined.276*277* @throws SQLException if a database access error occurs278*/279void close() throws SQLException;280281/**282* Retrieves whether this {@code Connection} object has been283* closed. A connection is closed if the method {@code close}284* has been called on it or if certain fatal errors have occurred.285* This method is guaranteed to return {@code true} only when286* it is called after the method {@code Connection.close} has287* been called.288* <P>289* This method generally cannot be called to determine whether a290* connection to a database is valid or invalid. A typical client291* can determine that a connection is invalid by catching any292* exceptions that might be thrown when an operation is attempted.293*294* @return {@code true} if this {@code Connection} object295* is closed; {@code false} if it is still open296* @throws SQLException if a database access error occurs297*/298boolean isClosed() throws SQLException;299300//======================================================================301// Advanced features:302303/**304* Retrieves a {@code DatabaseMetaData} object that contains305* metadata about the database to which this306* {@code Connection} object represents a connection.307* The metadata includes information about the database's308* tables, its supported SQL grammar, its stored309* procedures, the capabilities of this connection, and so on.310*311* @return a {@code DatabaseMetaData} object for this312* {@code Connection} object313* @throws SQLException if a database access error occurs314* or this method is called on a closed connection315*/316DatabaseMetaData getMetaData() throws SQLException;317318/**319* Puts this connection in read-only mode as a hint to the driver to enable320* database optimizations.321*322* <P><B>Note:</B> This method cannot be called during a transaction.323*324* @param readOnly {@code true} enables read-only mode;325* {@code false} disables it326* @throws SQLException if a database access error occurs, this327* method is called on a closed connection or this328* method is called during a transaction329*/330void setReadOnly(boolean readOnly) throws SQLException;331332/**333* Retrieves whether this {@code Connection}334* object is in read-only mode.335*336* @return {@code true} if this {@code Connection} object337* is read-only; {@code false} otherwise338* @throws SQLException if a database access error occurs339* or this method is called on a closed connection340*/341boolean isReadOnly() throws SQLException;342343/**344* Sets the given catalog name in order to select345* a subspace of this {@code Connection} object's database346* in which to work.347* <P>348* If the driver does not support catalogs, it will349* silently ignore this request.350* <p>351* Calling {@code setCatalog} has no effect on previously created or prepared352* {@code Statement} objects. It is implementation defined whether a DBMS353* prepare operation takes place immediately when the {@code Connection}354* method {@code prepareStatement} or {@code prepareCall} is invoked.355* For maximum portability, {@code setCatalog} should be called before a356* {@code Statement} is created or prepared.357*358* @param catalog the name of a catalog (subspace in this359* {@code Connection} object's database) in which to work360* @throws SQLException if a database access error occurs361* or this method is called on a closed connection362* @see #getCatalog363*/364void setCatalog(String catalog) throws SQLException;365366/**367* Retrieves this {@code Connection} object's current catalog name.368*369* @return the current catalog name or {@code null} if there is none370* @throws SQLException if a database access error occurs371* or this method is called on a closed connection372* @see #setCatalog373*/374String getCatalog() throws SQLException;375376/**377* A constant indicating that transactions are not supported.378*/379int TRANSACTION_NONE = 0;380381/**382* A constant indicating that383* dirty reads, non-repeatable reads and phantom reads can occur.384* This level allows a row changed by one transaction to be read385* by another transaction before any changes in that row have been386* committed (a "dirty read"). If any of the changes are rolled back,387* the second transaction will have retrieved an invalid row.388*/389int TRANSACTION_READ_UNCOMMITTED = 1;390391/**392* A constant indicating that393* dirty reads are prevented; non-repeatable reads and phantom394* reads can occur. This level only prohibits a transaction395* from reading a row with uncommitted changes in it.396*/397int TRANSACTION_READ_COMMITTED = 2;398399/**400* A constant indicating that401* dirty reads and non-repeatable reads are prevented; phantom402* reads can occur. This level prohibits a transaction from403* reading a row with uncommitted changes in it, and it also404* prohibits the situation where one transaction reads a row,405* a second transaction alters the row, and the first transaction406* rereads the row, getting different values the second time407* (a "non-repeatable read").408*/409int TRANSACTION_REPEATABLE_READ = 4;410411/**412* A constant indicating that413* dirty reads, non-repeatable reads and phantom reads are prevented.414* This level includes the prohibitions in415* {@code TRANSACTION_REPEATABLE_READ} and further prohibits the416* situation where one transaction reads all rows that satisfy417* a {@code WHERE} condition, a second transaction inserts a row that418* satisfies that {@code WHERE} condition, and the first transaction419* rereads for the same condition, retrieving the additional420* "phantom" row in the second read.421*/422int TRANSACTION_SERIALIZABLE = 8;423424/**425* Attempts to change the transaction isolation level for this426* {@code Connection} object to the one given.427* The constants defined in the interface {@code Connection}428* are the possible transaction isolation levels.429* <P>430* <B>Note:</B> If this method is called during a transaction, the result431* is implementation-defined.432*433* @param level one of the following {@code Connection} constants:434* {@code Connection.TRANSACTION_READ_UNCOMMITTED},435* {@code Connection.TRANSACTION_READ_COMMITTED},436* {@code Connection.TRANSACTION_REPEATABLE_READ}, or437* {@code Connection.TRANSACTION_SERIALIZABLE}.438* (Note that {@code Connection.TRANSACTION_NONE} cannot be used439* because it specifies that transactions are not supported.)440* @throws SQLException if a database access error occurs, this441* method is called on a closed connection442* or the given parameter is not one of the {@code Connection}443* constants444* @see DatabaseMetaData#supportsTransactionIsolationLevel445* @see #getTransactionIsolation446*/447void setTransactionIsolation(int level) throws SQLException;448449/**450* Retrieves this {@code Connection} object's current451* transaction isolation level.452*453* @return the current transaction isolation level, which will be one454* of the following constants:455* {@code Connection.TRANSACTION_READ_UNCOMMITTED},456* {@code Connection.TRANSACTION_READ_COMMITTED},457* {@code Connection.TRANSACTION_REPEATABLE_READ},458* {@code Connection.TRANSACTION_SERIALIZABLE}, or459* {@code Connection.TRANSACTION_NONE}.460* @throws SQLException if a database access error occurs461* or this method is called on a closed connection462* @see #setTransactionIsolation463*/464int getTransactionIsolation() throws SQLException;465466/**467* Retrieves the first warning reported by calls on this468* {@code Connection} object. If there is more than one469* warning, subsequent warnings will be chained to the first one470* and can be retrieved by calling the method471* {@code SQLWarning.getNextWarning} on the warning472* that was retrieved previously.473* <P>474* This method may not be475* called on a closed connection; doing so will cause an476* {@code SQLException} to be thrown.477*478* <P><B>Note:</B> Subsequent warnings will be chained to this479* SQLWarning.480*481* @return the first {@code SQLWarning} object or {@code null}482* if there are none483* @throws SQLException if a database access error occurs or484* this method is called on a closed connection485* @see SQLWarning486*/487SQLWarning getWarnings() throws SQLException;488489/**490* Clears all warnings reported for this {@code Connection} object.491* After a call to this method, the method {@code getWarnings}492* returns {@code null} until a new warning is493* reported for this {@code Connection} object.494*495* @throws SQLException if a database access error occurs496* or this method is called on a closed connection497*/498void clearWarnings() throws SQLException;499500501//--------------------------JDBC 2.0-----------------------------502503/**504* Creates a {@code Statement} object that will generate505* {@code ResultSet} objects with the given type and concurrency.506* This method is the same as the {@code createStatement} method507* above, but it allows the default result set508* type and concurrency to be overridden.509* The holdability of the created result sets can be determined by510* calling {@link #getHoldability}.511*512* @param resultSetType a result set type; one of513* {@code ResultSet.TYPE_FORWARD_ONLY},514* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or515* {@code ResultSet.TYPE_SCROLL_SENSITIVE}516* @param resultSetConcurrency a concurrency type; one of517* {@code ResultSet.CONCUR_READ_ONLY} or518* {@code ResultSet.CONCUR_UPDATABLE}519* @return a new {@code Statement} object that will generate520* {@code ResultSet} objects with the given type and521* concurrency522* @throws SQLException if a database access error occurs, this523* method is called on a closed connection524* or the given parameters are not {@code ResultSet}525* constants indicating type and concurrency526* @throws SQLFeatureNotSupportedException if the JDBC driver does not support527* this method or this method is not supported for the specified result528* set type and result set concurrency.529* @since 1.2530*/531Statement createStatement(int resultSetType, int resultSetConcurrency)532throws SQLException;533534/**535*536* Creates a {@code PreparedStatement} object that will generate537* {@code ResultSet} objects with the given type and concurrency.538* This method is the same as the {@code prepareStatement} method539* above, but it allows the default result set540* type and concurrency to be overridden.541* The holdability of the created result sets can be determined by542* calling {@link #getHoldability}.543*544* @param sql a {@code String} object that is the SQL statement to545* be sent to the database; may contain one or more '?' IN546* parameters547* @param resultSetType a result set type; one of548* {@code ResultSet.TYPE_FORWARD_ONLY},549* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or550* {@code ResultSet.TYPE_SCROLL_SENSITIVE}551* @param resultSetConcurrency a concurrency type; one of552* {@code ResultSet.CONCUR_READ_ONLY} or553* {@code ResultSet.CONCUR_UPDATABLE}554* @return a new PreparedStatement object containing the555* pre-compiled SQL statement that will produce {@code ResultSet}556* objects with the given type and concurrency557* @throws SQLException if a database access error occurs, this558* method is called on a closed connection559* or the given parameters are not {@code ResultSet}560* constants indicating type and concurrency561* @throws SQLFeatureNotSupportedException if the JDBC driver does not support562* this method or this method is not supported for the specified result563* set type and result set concurrency.564* @since 1.2565*/566PreparedStatement prepareStatement(String sql, int resultSetType,567int resultSetConcurrency)568throws SQLException;569570/**571* Creates a {@code CallableStatement} object that will generate572* {@code ResultSet} objects with the given type and concurrency.573* This method is the same as the {@code prepareCall} method574* above, but it allows the default result set575* type and concurrency to be overridden.576* The holdability of the created result sets can be determined by577* calling {@link #getHoldability}.578*579* @param sql a {@code String} object that is the SQL statement to580* be sent to the database; may contain on or more '?' parameters581* @param resultSetType a result set type; one of582* {@code ResultSet.TYPE_FORWARD_ONLY},583* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or584* {@code ResultSet.TYPE_SCROLL_SENSITIVE}585* @param resultSetConcurrency a concurrency type; one of586* {@code ResultSet.CONCUR_READ_ONLY} or587* {@code ResultSet.CONCUR_UPDATABLE}588* @return a new {@code CallableStatement} object containing the589* pre-compiled SQL statement that will produce {@code ResultSet}590* objects with the given type and concurrency591* @throws SQLException if a database access error occurs, this method592* is called on a closed connection593* or the given parameters are not {@code ResultSet}594* constants indicating type and concurrency595* @throws SQLFeatureNotSupportedException if the JDBC driver does not support596* this method or this method is not supported for the specified result597* set type and result set concurrency.598* @since 1.2599*/600CallableStatement prepareCall(String sql, int resultSetType,601int resultSetConcurrency) throws SQLException;602603/**604* Retrieves the {@code Map} object associated with this605* {@code Connection} object.606* Unless the application has added an entry, the type map returned607* will be empty.608* <p>609* You must invoke {@code setTypeMap} after making changes to the610* {@code Map} object returned from611* {@code getTypeMap} as a JDBC driver may create an internal612* copy of the {@code Map} object passed to {@code setTypeMap}:613*614* <pre>615* Map<String,Class<?>> myMap = con.getTypeMap();616* myMap.put("mySchemaName.ATHLETES", Athletes.class);617* con.setTypeMap(myMap);618* </pre>619* @return the {@code java.util.Map} object associated620* with this {@code Connection} object621* @throws SQLException if a database access error occurs622* or this method is called on a closed connection623* @throws SQLFeatureNotSupportedException if the JDBC driver does not support624* this method625* @since 1.2626* @see #setTypeMap627*/628java.util.Map<String,Class<?>> getTypeMap() throws SQLException;629630/**631* Installs the given {@code TypeMap} object as the type map for632* this {@code Connection} object. The type map will be used for the633* custom mapping of SQL structured types and distinct types.634* <p>635* You must set the values for the {@code TypeMap} prior to636* callng {@code setMap} as a JDBC driver may create an internal copy637* of the {@code TypeMap}:638*639* <pre>640* Map myMap<String,Class<?>> = new HashMap<String,Class<?>>();641* myMap.put("mySchemaName.ATHLETES", Athletes.class);642* con.setTypeMap(myMap);643* </pre>644* @param map the {@code java.util.Map} object to install645* as the replacement for this {@code Connection}646* object's default type map647* @throws SQLException if a database access error occurs, this648* method is called on a closed connection or649* the given parameter is not a {@code java.util.Map}650* object651* @throws SQLFeatureNotSupportedException if the JDBC driver does not support652* this method653* @since 1.2654* @see #getTypeMap655*/656void setTypeMap(java.util.Map<String,Class<?>> map) throws SQLException;657658//--------------------------JDBC 3.0-----------------------------659660661/**662* Changes the default holdability of {@code ResultSet} objects663* created using this {@code Connection} object to the given664* holdability. The default holdability of {@code ResultSet} objects665* can be determined by invoking666* {@link DatabaseMetaData#getResultSetHoldability}.667*668* @param holdability a {@code ResultSet} holdability constant; one of669* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or670* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}671* @throws SQLException if a database access occurs, this method is called672* on a closed connection, or the given parameter673* is not a {@code ResultSet} constant indicating holdability674* @throws SQLFeatureNotSupportedException if the given holdability is not supported675* @see #getHoldability676* @see DatabaseMetaData#getResultSetHoldability677* @see ResultSet678* @since 1.4679*/680void setHoldability(int holdability) throws SQLException;681682/**683* Retrieves the current holdability of {@code ResultSet} objects684* created using this {@code Connection} object.685*686* @return the holdability, one of687* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or688* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}689* @throws SQLException if a database access error occurs690* or this method is called on a closed connection691* @see #setHoldability692* @see DatabaseMetaData#getResultSetHoldability693* @see ResultSet694* @since 1.4695*/696int getHoldability() throws SQLException;697698/**699* Creates an unnamed savepoint in the current transaction and700* returns the new {@code Savepoint} object that represents it.701*702*<p> if setSavepoint is invoked outside of an active transaction, a transaction will be started at this newly created703*savepoint.704*705* @return the new {@code Savepoint} object706* @throws SQLException if a database access error occurs,707* this method is called while participating in a distributed transaction,708* this method is called on a closed connection709* or this {@code Connection} object is currently in710* auto-commit mode711* @throws SQLFeatureNotSupportedException if the JDBC driver does not support712* this method713* @see Savepoint714* @since 1.4715*/716Savepoint setSavepoint() throws SQLException;717718/**719* Creates a savepoint with the given name in the current transaction720* and returns the new {@code Savepoint} object that represents it.721*722* <p> if setSavepoint is invoked outside of an active transaction, a transaction will be started at this newly created723*savepoint.724*725* @param name a {@code String} containing the name of the savepoint726* @return the new {@code Savepoint} object727* @throws SQLException if a database access error occurs,728* this method is called while participating in a distributed transaction,729* this method is called on a closed connection730* or this {@code Connection} object is currently in731* auto-commit mode732* @throws SQLFeatureNotSupportedException if the JDBC driver does not support733* this method734* @see Savepoint735* @since 1.4736*/737Savepoint setSavepoint(String name) throws SQLException;738739/**740* Undoes all changes made after the given {@code Savepoint} object741* was set.742* <P>743* This method should be used only when auto-commit has been disabled.744*745* @param savepoint the {@code Savepoint} object to roll back to746* @throws SQLException if a database access error occurs,747* this method is called while participating in a distributed transaction,748* this method is called on a closed connection,749* the {@code Savepoint} object is no longer valid,750* or this {@code Connection} object is currently in751* auto-commit mode752* @throws SQLFeatureNotSupportedException if the JDBC driver does not support753* this method754* @see Savepoint755* @see #rollback756* @since 1.4757*/758void rollback(Savepoint savepoint) throws SQLException;759760/**761* Removes the specified {@code Savepoint} and subsequent {@code Savepoint} objects from the current762* transaction. Any reference to the savepoint after it have been removed763* will cause an {@code SQLException} to be thrown.764*765* @param savepoint the {@code Savepoint} object to be removed766* @throws SQLException if a database access error occurs, this767* method is called on a closed connection or768* the given {@code Savepoint} object is not a valid769* savepoint in the current transaction770* @throws SQLFeatureNotSupportedException if the JDBC driver does not support771* this method772* @since 1.4773*/774void releaseSavepoint(Savepoint savepoint) throws SQLException;775776/**777* Creates a {@code Statement} object that will generate778* {@code ResultSet} objects with the given type, concurrency,779* and holdability.780* This method is the same as the {@code createStatement} method781* above, but it allows the default result set782* type, concurrency, and holdability to be overridden.783*784* @param resultSetType one of the following {@code ResultSet}785* constants:786* {@code ResultSet.TYPE_FORWARD_ONLY},787* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or788* {@code ResultSet.TYPE_SCROLL_SENSITIVE}789* @param resultSetConcurrency one of the following {@code ResultSet}790* constants:791* {@code ResultSet.CONCUR_READ_ONLY} or792* {@code ResultSet.CONCUR_UPDATABLE}793* @param resultSetHoldability one of the following {@code ResultSet}794* constants:795* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or796* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}797* @return a new {@code Statement} object that will generate798* {@code ResultSet} objects with the given type,799* concurrency, and holdability800* @throws SQLException if a database access error occurs, this801* method is called on a closed connection802* or the given parameters are not {@code ResultSet}803* constants indicating type, concurrency, and holdability804* @throws SQLFeatureNotSupportedException if the JDBC driver does not support805* this method or this method is not supported for the specified result806* set type, result set holdability and result set concurrency.807* @see ResultSet808* @since 1.4809*/810Statement createStatement(int resultSetType, int resultSetConcurrency,811int resultSetHoldability) throws SQLException;812813/**814* Creates a {@code PreparedStatement} object that will generate815* {@code ResultSet} objects with the given type, concurrency,816* and holdability.817* <P>818* This method is the same as the {@code prepareStatement} method819* above, but it allows the default result set820* type, concurrency, and holdability to be overridden.821*822* @param sql a {@code String} object that is the SQL statement to823* be sent to the database; may contain one or more '?' IN824* parameters825* @param resultSetType one of the following {@code ResultSet}826* constants:827* {@code ResultSet.TYPE_FORWARD_ONLY},828* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or829* {@code ResultSet.TYPE_SCROLL_SENSITIVE}830* @param resultSetConcurrency one of the following {@code ResultSet}831* constants:832* {@code ResultSet.CONCUR_READ_ONLY} or833* {@code ResultSet.CONCUR_UPDATABLE}834* @param resultSetHoldability one of the following {@code ResultSet}835* constants:836* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or837* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}838* @return a new {@code PreparedStatement} object, containing the839* pre-compiled SQL statement, that will generate840* {@code ResultSet} objects with the given type,841* concurrency, and holdability842* @throws SQLException if a database access error occurs, this843* method is called on a closed connection844* or the given parameters are not {@code ResultSet}845* constants indicating type, concurrency, and holdability846* @throws SQLFeatureNotSupportedException if the JDBC driver does not support847* this method or this method is not supported for the specified result848* set type, result set holdability and result set concurrency.849* @see ResultSet850* @since 1.4851*/852PreparedStatement prepareStatement(String sql, int resultSetType,853int resultSetConcurrency, int resultSetHoldability)854throws SQLException;855856/**857* Creates a {@code CallableStatement} object that will generate858* {@code ResultSet} objects with the given type and concurrency.859* This method is the same as the {@code prepareCall} method860* above, but it allows the default result set861* type, result set concurrency type and holdability to be overridden.862*863* @param sql a {@code String} object that is the SQL statement to864* be sent to the database; may contain on or more '?' parameters865* @param resultSetType one of the following {@code ResultSet}866* constants:867* {@code ResultSet.TYPE_FORWARD_ONLY},868* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or869* {@code ResultSet.TYPE_SCROLL_SENSITIVE}870* @param resultSetConcurrency one of the following {@code ResultSet}871* constants:872* {@code ResultSet.CONCUR_READ_ONLY} or873* {@code ResultSet.CONCUR_UPDATABLE}874* @param resultSetHoldability one of the following {@code ResultSet}875* constants:876* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or877* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}878* @return a new {@code CallableStatement} object, containing the879* pre-compiled SQL statement, that will generate880* {@code ResultSet} objects with the given type,881* concurrency, and holdability882* @throws SQLException if a database access error occurs, this883* method is called on a closed connection884* or the given parameters are not {@code ResultSet}885* constants indicating type, concurrency, and holdability886* @throws SQLFeatureNotSupportedException if the JDBC driver does not support887* this method or this method is not supported for the specified result888* set type, result set holdability and result set concurrency.889* @see ResultSet890* @since 1.4891*/892CallableStatement prepareCall(String sql, int resultSetType,893int resultSetConcurrency,894int resultSetHoldability) throws SQLException;895896897/**898* Creates a default {@code PreparedStatement} object that has899* the capability to retrieve auto-generated keys. The given constant900* tells the driver whether it should make auto-generated keys901* available for retrieval. This parameter is ignored if the SQL statement902* is not an {@code INSERT} statement, or an SQL statement able to return903* auto-generated keys (the list of such statements is vendor-specific).904* <P>905* <B>Note:</B> This method is optimized for handling906* parametric SQL statements that benefit from precompilation. If907* the driver supports precompilation,908* the method {@code prepareStatement} will send909* the statement to the database for precompilation. Some drivers910* may not support precompilation. In this case, the statement may911* not be sent to the database until the {@code PreparedStatement}912* object is executed. This has no direct effect on users; however, it does913* affect which methods throw certain SQLExceptions.914* <P>915* Result sets created using the returned {@code PreparedStatement}916* object will by default be type {@code TYPE_FORWARD_ONLY}917* and have a concurrency level of {@code CONCUR_READ_ONLY}.918* The holdability of the created result sets can be determined by919* calling {@link #getHoldability}.920*921* @param sql an SQL statement that may contain one or more '?' IN922* parameter placeholders923* @param autoGeneratedKeys a flag indicating whether auto-generated keys924* should be returned; one of925* {@code Statement.RETURN_GENERATED_KEYS} or926* {@code Statement.NO_GENERATED_KEYS}927* @return a new {@code PreparedStatement} object, containing the928* pre-compiled SQL statement, that will have the capability of929* returning auto-generated keys930* @throws SQLException if a database access error occurs, this931* method is called on a closed connection932* or the given parameter is not a {@code Statement}933* constant indicating whether auto-generated keys should be934* returned935* @throws SQLFeatureNotSupportedException if the JDBC driver does not support936* this method with a constant of Statement.RETURN_GENERATED_KEYS937* @since 1.4938*/939PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)940throws SQLException;941942/**943* Creates a default {@code PreparedStatement} object capable944* of returning the auto-generated keys designated by the given array.945* This array contains the indexes of the columns in the target946* table that contain the auto-generated keys that should be made947* available. The driver will ignore the array if the SQL statement948* is not an {@code INSERT} statement, or an SQL statement able to return949* auto-generated keys (the list of such statements is vendor-specific).950*<p>951* An SQL statement with or without IN parameters can be952* pre-compiled and stored in a {@code PreparedStatement} object. This953* object can then be used to efficiently execute this statement954* multiple times.955* <P>956* <B>Note:</B> This method is optimized for handling957* parametric SQL statements that benefit from precompilation. If958* the driver supports precompilation,959* the method {@code prepareStatement} will send960* the statement to the database for precompilation. Some drivers961* may not support precompilation. In this case, the statement may962* not be sent to the database until the {@code PreparedStatement}963* object is executed. This has no direct effect on users; however, it does964* affect which methods throw certain SQLExceptions.965* <P>966* Result sets created using the returned {@code PreparedStatement}967* object will by default be type {@code TYPE_FORWARD_ONLY}968* and have a concurrency level of {@code CONCUR_READ_ONLY}.969* The holdability of the created result sets can be determined by970* calling {@link #getHoldability}.971*972* @param sql an SQL statement that may contain one or more '?' IN973* parameter placeholders974* @param columnIndexes an array of column indexes indicating the columns975* that should be returned from the inserted row or rows976* @return a new {@code PreparedStatement} object, containing the977* pre-compiled statement, that is capable of returning the978* auto-generated keys designated by the given array of column979* indexes980* @throws SQLException if a database access error occurs981* or this method is called on a closed connection982* @throws SQLFeatureNotSupportedException if the JDBC driver does not support983* this method984*985* @since 1.4986*/987PreparedStatement prepareStatement(String sql, int columnIndexes[])988throws SQLException;989990/**991* Creates a default {@code PreparedStatement} object capable992* of returning the auto-generated keys designated by the given array.993* This array contains the names of the columns in the target994* table that contain the auto-generated keys that should be returned.995* The driver will ignore the array if the SQL statement996* is not an {@code INSERT} statement, or an SQL statement able to return997* auto-generated keys (the list of such statements is vendor-specific).998* <P>999* An SQL statement with or without IN parameters can be1000* pre-compiled and stored in a {@code PreparedStatement} object. This1001* object can then be used to efficiently execute this statement1002* multiple times.1003* <P>1004* <B>Note:</B> This method is optimized for handling1005* parametric SQL statements that benefit from precompilation. If1006* the driver supports precompilation,1007* the method {@code prepareStatement} will send1008* the statement to the database for precompilation. Some drivers1009* may not support precompilation. In this case, the statement may1010* not be sent to the database until the {@code PreparedStatement}1011* object is executed. This has no direct effect on users; however, it does1012* affect which methods throw certain SQLExceptions.1013* <P>1014* Result sets created using the returned {@code PreparedStatement}1015* object will by default be type {@code TYPE_FORWARD_ONLY}1016* and have a concurrency level of {@code CONCUR_READ_ONLY}.1017* The holdability of the created result sets can be determined by1018* calling {@link #getHoldability}.1019*1020* @param sql an SQL statement that may contain one or more '?' IN1021* parameter placeholders1022* @param columnNames an array of column names indicating the columns1023* that should be returned from the inserted row or rows1024* @return a new {@code PreparedStatement} object, containing the1025* pre-compiled statement, that is capable of returning the1026* auto-generated keys designated by the given array of column1027* names1028* @throws SQLException if a database access error occurs1029* or this method is called on a closed connection1030* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1031* this method1032*1033* @since 1.41034*/1035PreparedStatement prepareStatement(String sql, String columnNames[])1036throws SQLException;10371038/**1039* Constructs an object that implements the {@code Clob} interface. The object1040* returned initially contains no data. The {@code setAsciiStream},1041* {@code setCharacterStream} and {@code setString} methods of1042* the {@code Clob} interface may be used to add data to the {@code Clob}.1043* @return An object that implements the {@code Clob} interface1044* @throws SQLException if an object that implements the1045* {@code Clob} interface can not be constructed, this method is1046* called on a closed connection or a database access error occurs.1047* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1048* this data type1049*1050* @since 1.61051*/1052Clob createClob() throws SQLException;10531054/**1055* Constructs an object that implements the {@code Blob} interface. The object1056* returned initially contains no data. The {@code setBinaryStream} and1057* {@code setBytes} methods of the {@code Blob} interface may be used to add data to1058* the {@code Blob}.1059* @return An object that implements the {@code Blob} interface1060* @throws SQLException if an object that implements the1061* {@code Blob} interface can not be constructed, this method is1062* called on a closed connection or a database access error occurs.1063* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1064* this data type1065*1066* @since 1.61067*/1068Blob createBlob() throws SQLException;10691070/**1071* Constructs an object that implements the {@code NClob} interface. The object1072* returned initially contains no data. The {@code setAsciiStream},1073* {@code setCharacterStream} and {@code setString} methods of the {@code NClob} interface may1074* be used to add data to the {@code NClob}.1075* @return An object that implements the {@code NClob} interface1076* @throws SQLException if an object that implements the1077* {@code NClob} interface can not be constructed, this method is1078* called on a closed connection or a database access error occurs.1079* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1080* this data type1081*1082* @since 1.61083*/1084NClob createNClob() throws SQLException;10851086/**1087* Constructs an object that implements the {@code SQLXML} interface. The object1088* returned initially contains no data. The {@code createXmlStreamWriter} object and1089* {@code setString} method of the {@code SQLXML} interface may be used to add data to the {@code SQLXML}1090* object.1091* @return An object that implements the {@code SQLXML} interface1092* @throws SQLException if an object that implements the {@code SQLXML} interface can not1093* be constructed, this method is1094* called on a closed connection or a database access error occurs.1095* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1096* this data type1097* @since 1.61098*/1099SQLXML createSQLXML() throws SQLException;11001101/**1102* Returns true if the connection has not been closed and is still valid.1103* The driver shall submit a query on the connection or use some other1104* mechanism that positively verifies the connection is still valid when1105* this method is called.1106* <p>1107* The query submitted by the driver to validate the connection shall be1108* executed in the context of the current transaction.1109*1110* @param timeout - The time in seconds to wait for the database operation1111* used to validate the connection to complete. If1112* the timeout period expires before the operation1113* completes, this method returns false. A value of1114* 0 indicates a timeout is not applied to the1115* database operation.1116*1117* @return true if the connection is valid, false otherwise1118* @throws SQLException if the value supplied for {@code timeout}1119* is less than 01120* @since 1.61121*1122* @see java.sql.DatabaseMetaData#getClientInfoProperties1123*/1124boolean isValid(int timeout) throws SQLException;11251126/**1127* Sets the value of the client info property specified by name to the1128* value specified by value.1129* <p>1130* Applications may use the {@code DatabaseMetaData.getClientInfoProperties}1131* method to determine the client info properties supported by the driver1132* and the maximum length that may be specified for each property.1133* <p>1134* The driver stores the value specified in a suitable location in the1135* database. For example in a special register, session parameter, or1136* system table column. For efficiency the driver may defer setting the1137* value in the database until the next time a statement is executed or1138* prepared. Other than storing the client information in the appropriate1139* place in the database, these methods shall not alter the behavior of1140* the connection in anyway. The values supplied to these methods are1141* used for accounting, diagnostics and debugging purposes only.1142* <p>1143* The driver shall generate a warning if the client info name specified1144* is not recognized by the driver.1145* <p>1146* If the value specified to this method is greater than the maximum1147* length for the property the driver may either truncate the value and1148* generate a warning or generate a {@code SQLClientInfoException}. If the driver1149* generates a {@code SQLClientInfoException}, the value specified was not set on the1150* connection.1151* <p>1152* The following are standard client info properties. Drivers are not1153* required to support these properties however if the driver supports a1154* client info property that can be described by one of the standard1155* properties, the standard property name should be used.1156*1157* <ul>1158* <li>ApplicationName - The name of the application currently utilizing1159* the connection</li>1160* <li>ClientUser - The name of the user that the application using1161* the connection is performing work for. This may1162* not be the same as the user name that was used1163* in establishing the connection.</li>1164* <li>ClientHostname - The hostname of the computer the application1165* using the connection is running on.</li>1166* </ul>1167*1168* @param name The name of the client info property to set1169* @param value The value to set the client info property to. If the1170* value is null, the current value of the specified1171* property is cleared.1172*1173* @throws SQLClientInfoException if the database server returns an error while1174* setting the client info value on the database server or this method1175* is called on a closed connection1176*1177* @since 1.61178*/1179void setClientInfo(String name, String value)1180throws SQLClientInfoException;11811182/**1183* Sets the value of the connection's client info properties. The1184* {@code Properties} object contains the names and values of the client info1185* properties to be set. The set of client info properties contained in1186* the properties list replaces the current set of client info properties1187* on the connection. If a property that is currently set on the1188* connection is not present in the properties list, that property is1189* cleared. Specifying an empty properties list will clear all of the1190* properties on the connection. See {@code setClientInfo (String, String)} for1191* more information.1192* <p>1193* If an error occurs in setting any of the client info properties, a1194* {@code SQLClientInfoException} is thrown. The {@code SQLClientInfoException}1195* contains information indicating which client info properties were not set.1196* The state of the client information is unknown because1197* some databases do not allow multiple client info properties to be set1198* atomically. For those databases, one or more properties may have been1199* set before the error occurred.1200*1201*1202* @param properties the list of client info properties to set1203*1204* @see java.sql.Connection#setClientInfo(String, String) setClientInfo(String, String)1205* @since 1.61206*1207* @throws SQLClientInfoException if the database server returns an error while1208* setting the clientInfo values on the database server or this method1209* is called on a closed connection1210*1211*/1212void setClientInfo(Properties properties)1213throws SQLClientInfoException;12141215/**1216* Returns the value of the client info property specified by name. This1217* method may return null if the specified client info property has not1218* been set and does not have a default value. This method will also1219* return null if the specified client info property name is not supported1220* by the driver.1221* <p>1222* Applications may use the {@code DatabaseMetaData.getClientInfoProperties}1223* method to determine the client info properties supported by the driver.1224*1225* @param name The name of the client info property to retrieve1226*1227* @return The value of the client info property specified1228*1229* @throws SQLException if the database server returns an error when1230* fetching the client info value from the database1231* or this method is called on a closed connection1232*1233* @since 1.61234*1235* @see java.sql.DatabaseMetaData#getClientInfoProperties1236*/1237String getClientInfo(String name)1238throws SQLException;12391240/**1241* Returns a list containing the name and current value of each client info1242* property supported by the driver. The value of a client info property1243* may be null if the property has not been set and does not have a1244* default value.1245*1246* @return A {@code Properties} object that contains the name and current value of1247* each of the client info properties supported by the driver.1248*1249* @throws SQLException if the database server returns an error when1250* fetching the client info values from the database1251* or this method is called on a closed connection1252*1253* @since 1.61254*/1255Properties getClientInfo()1256throws SQLException;12571258/**1259* Factory method for creating Array objects.1260*<p>1261* <b>Note: </b>When {@code createArrayOf} is used to create an array object1262* that maps to a primitive data type, then it is implementation-defined1263* whether the {@code Array} object is an array of that primitive1264* data type or an array of {@code Object}.1265* <p>1266* <b>Note: </b>The JDBC driver is responsible for mapping the elements1267* {@code Object} array to the default JDBC SQL type defined in1268* java.sql.Types for the given class of {@code Object}. The default1269* mapping is specified in Appendix B of the JDBC specification. If the1270* resulting JDBC type is not the appropriate type for the given typeName then1271* it is implementation defined whether an {@code SQLException} is1272* thrown or the driver supports the resulting conversion.1273*1274* @param typeName the SQL name of the type the elements of the array map to. The typeName is a1275* database-specific name which may be the name of a built-in type, a user-defined type or a standard SQL type supported by this database. This1276* is the value returned by {@code Array.getBaseTypeName}1277* @param elements the elements that populate the returned object1278* @return an Array object whose elements map to the specified SQL type1279* @throws SQLException if a database error occurs, the JDBC type is not1280* appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection1281* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this data type1282* @since 1.61283*/1284Array createArrayOf(String typeName, Object[] elements) throws1285SQLException;12861287/**1288* Factory method for creating Struct objects.1289*1290* @param typeName the SQL type name of the SQL structured type that this {@code Struct}1291* object maps to. The typeName is the name of a user-defined type that1292* has been defined for this database. It is the value returned by1293* {@code Struct.getSQLTypeName}.12941295* @param attributes the attributes that populate the returned object1296* @return a Struct object that maps to the given SQL type and is populated with the given attributes1297* @throws SQLException if a database error occurs, the typeName is null or this method is called on a closed connection1298* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this data type1299* @since 1.61300*/1301Struct createStruct(String typeName, Object[] attributes)1302throws SQLException;13031304//--------------------------JDBC 4.1 -----------------------------13051306/**1307* Sets the given schema name to access.1308* <P>1309* If the driver does not support schemas, it will1310* silently ignore this request.1311* <p>1312* Calling {@code setSchema} has no effect on previously created or prepared1313* {@code Statement} objects. It is implementation defined whether a DBMS1314* prepare operation takes place immediately when the {@code Connection}1315* method {@code prepareStatement} or {@code prepareCall} is invoked.1316* For maximum portability, {@code setSchema} should be called before a1317* {@code Statement} is created or prepared.1318*1319* @param schema the name of a schema in which to work1320* @throws SQLException if a database access error occurs1321* or this method is called on a closed connection1322* @see #getSchema1323* @since 1.71324*/1325void setSchema(String schema) throws SQLException;13261327/**1328* Retrieves this {@code Connection} object's current schema name.1329*1330* @return the current schema name or {@code null} if there is none1331* @throws SQLException if a database access error occurs1332* or this method is called on a closed connection1333* @see #setSchema1334* @since 1.71335*/1336String getSchema() throws SQLException;13371338/**1339* Terminates an open connection. Calling {@code abort} results in:1340* <ul>1341* <li>The connection marked as closed1342* <li>Closes any physical connection to the database1343* <li>Releases resources used by the connection1344* <li>Insures that any thread that is currently accessing the connection1345* will either progress to completion or throw an {@code SQLException}.1346* </ul>1347* <p>1348* Calling {@code abort} marks the connection closed and releases any1349* resources. Calling {@code abort} on a closed connection is a1350* no-op.1351* <p>1352* It is possible that the aborting and releasing of the resources that are1353* held by the connection can take an extended period of time. When the1354* {@code abort} method returns, the connection will have been marked as1355* closed and the {@code Executor} that was passed as a parameter to abort1356* may still be executing tasks to release resources.1357* <p>1358* This method checks to see that there is an {@code SQLPermission}1359* object before allowing the method to proceed. If a1360* {@code SecurityManager} exists and its1361* {@code checkPermission} method denies calling {@code abort},1362* this method throws a1363* {@code java.lang.SecurityException}.1364* @param executor The {@code Executor} implementation which will1365* be used by {@code abort}.1366* @throws java.sql.SQLException if a database access error occurs or1367* the {@code executor} is {@code null},1368* @throws java.lang.SecurityException if a security manager exists and its1369* {@code checkPermission} method denies calling {@code abort}1370* @see SecurityManager#checkPermission1371* @see Executor1372* @since 1.71373*/1374void abort(Executor executor) throws SQLException;13751376/**1377*1378* Sets the maximum period a {@code Connection} or1379* objects created from the {@code Connection}1380* will wait for the database to reply to any one request. If any1381* request remains unanswered, the waiting method will1382* return with a {@code SQLException}, and the {@code Connection}1383* or objects created from the {@code Connection} will be marked as1384* closed. Any subsequent use of1385* the objects, with the exception of the {@code close},1386* {@code isClosed} or {@code Connection.isValid}1387* methods, will result in a {@code SQLException}.1388* <p>1389* <b>Note</b>: This method is intended to address a rare but serious1390* condition where network partitions can cause threads issuing JDBC calls1391* to hang uninterruptedly in socket reads, until the OS TCP-TIMEOUT1392* (typically 10 minutes). This method is related to the1393* {@link #abort abort() } method which provides an administrator1394* thread a means to free any such threads in cases where the1395* JDBC connection is accessible to the administrator thread.1396* The {@code setNetworkTimeout} method will cover cases where1397* there is no administrator thread, or it has no access to the1398* connection. This method is severe in it's effects, and should be1399* given a high enough value so it is never triggered before any more1400* normal timeouts, such as transaction timeouts.1401* <p>1402* JDBC driver implementations may also choose to support the1403* {@code setNetworkTimeout} method to impose a limit on database1404* response time, in environments where no network is present.1405* <p>1406* Drivers may internally implement some or all of their API calls with1407* multiple internal driver-database transmissions, and it is left to the1408* driver implementation to determine whether the limit will be1409* applied always to the response to the API call, or to any1410* single request made during the API call.1411* <p>1412*1413* This method can be invoked more than once, such as to set a limit for an1414* area of JDBC code, and to reset to the default on exit from this area.1415* Invocation of this method has no impact on already outstanding1416* requests.1417* <p>1418* The {@code Statement.setQueryTimeout()} timeout value is independent of the1419* timeout value specified in {@code setNetworkTimeout}. If the query timeout1420* expires before the network timeout then the1421* statement execution will be canceled. If the network is still1422* active the result will be that both the statement and connection1423* are still usable. However if the network timeout expires before1424* the query timeout or if the statement timeout fails due to network1425* problems, the connection will be marked as closed, any resources held by1426* the connection will be released and both the connection and1427* statement will be unusable.1428* <p>1429* When the driver determines that the {@code setNetworkTimeout} timeout1430* value has expired, the JDBC driver marks the connection1431* closed and releases any resources held by the connection.1432* <p>1433*1434* This method checks to see that there is an {@code SQLPermission}1435* object before allowing the method to proceed. If a1436* {@code SecurityManager} exists and its1437* {@code checkPermission} method denies calling1438* {@code setNetworkTimeout}, this method throws a1439* {@code java.lang.SecurityException}.1440*1441* @param executor The {@code Executor} implementation which will1442* be used by {@code setNetworkTimeout}.1443* @param milliseconds The time in milliseconds to wait for the database1444* operation1445* to complete. If the JDBC driver does not support milliseconds, the1446* JDBC driver will round the value up to the nearest second. If the1447* timeout period expires before the operation1448* completes, a SQLException will be thrown.1449* A value of 0 indicates that there is not timeout for database operations.1450* @throws java.sql.SQLException if a database access error occurs, this1451* method is called on a closed connection,1452* the {@code executor} is {@code null},1453* or the value specified for {@code seconds} is less than 0.1454* @throws java.lang.SecurityException if a security manager exists and its1455* {@code checkPermission} method denies calling1456* {@code setNetworkTimeout}.1457* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1458* this method1459* @see SecurityManager#checkPermission1460* @see Statement#setQueryTimeout1461* @see #getNetworkTimeout1462* @see #abort1463* @see Executor1464* @since 1.71465*/1466void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException;146714681469/**1470* Retrieves the number of milliseconds the driver will1471* wait for a database request to complete.1472* If the limit is exceeded, a1473* {@code SQLException} is thrown.1474*1475* @return the current timeout limit in milliseconds; zero means there is1476* no limit1477* @throws SQLException if a database access error occurs or1478* this method is called on a closed {@code Connection}1479* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1480* this method1481* @see #setNetworkTimeout1482* @since 1.71483*/1484int getNetworkTimeout() throws SQLException;14851486// JDBC 4.314871488/**1489* Hints to the driver that a request, an independent unit of work, is beginning1490* on this connection. Each request is independent of all other requests1491* with regard to state local to the connection either on the client or the1492* server. Work done between {@code beginRequest}, {@code endRequest}1493* pairs does not depend on any other work done on the connection either as1494* part of another request or outside of any request. A request may include multiple1495* transactions. There may be dependencies on committed database state as1496* that is not local to the connection.1497* <p>1498* Local state is defined as any state associated with a Connection that is1499* local to the current Connection either in the client or the database that1500* is not transparently reproducible.1501* <p>1502* Calls to {@code beginRequest} and {@code endRequest} are not nested.1503* Multiple calls to {@code beginRequest} without an intervening call1504* to {@code endRequest} is not an error. The first {@code beginRequest} call1505* marks the start of the request and subsequent calls are treated as1506* a no-op1507* <p>1508* Use of {@code beginRequest} and {@code endRequest} is optional, vendor1509* specific and should largely be transparent. In particular1510* implementations may detect conditions that indicate dependence on1511* other work such as an open transaction. It is recommended though not1512* required that implementations throw a {@code SQLException} if there is an active1513* transaction and {@code beginRequest} is called.1514* Using these methods may improve performance or provide other benefits.1515* Consult your vendors documentation for additional information.1516* <p>1517* It is recommended to1518* enclose each unit of work in {@code beginRequest}, {@code endRequest}1519* pairs such that there is no open transaction at the beginning or end of1520* the request and no dependency on local state that crosses request1521* boundaries. Committed database state is not local.1522*1523* @implSpec1524* The default implementation is a no-op.1525*1526* @apiNote1527* This method is to be used by Connection pooling managers.1528* <p>1529* The pooling manager should call {@code beginRequest} on the underlying connection1530* prior to returning a connection to the caller.1531* <p>1532* The pooling manager does not need to call {@code beginRequest} if:1533* <ul>1534* <li>The connection pool caches {@code PooledConnection} objects</li>1535* <li>Returns a logical connection handle when {@code getConnection} is1536* called by the application</li>1537* <li>The logical {@code Connection} is closed by calling1538* {@code Connection.close} prior to returning the {@code PooledConnection}1539* to the cache.</li>1540* </ul>1541* @throws SQLException if an error occurs1542* @since 91543* @see endRequest1544* @see javax.sql.PooledConnection1545*/1546default void beginRequest() throws SQLException {1547// Default method takes no action1548}15491550/**1551* Hints to the driver that a request, an independent unit of work,1552* has completed. Calls to {@code beginRequest}1553* and {@code endRequest} are not nested. Multiple1554* calls to {@code endRequest} without an intervening call to {@code beginRequest}1555* is not an error. The first {@code endRequest} call1556* marks the request completed and subsequent calls are treated as1557* a no-op. If {@code endRequest} is called without an initial call to1558* {@code beginRequest} is a no-op.1559*<p>1560* The exact behavior of this method is vendor specific. In particular1561* implementations may detect conditions that indicate dependence on1562* other work such as an open transaction. It is recommended though not1563* required that implementations throw a {@code SQLException} if there is an active1564* transaction and {@code endRequest} is called.1565*1566* @implSpec1567* The default implementation is a no-op.1568* @apiNote1569*1570* This method is to be used by Connection pooling managers.1571* <p>1572* The pooling manager should call {@code endRequest} on the underlying connection1573* when the applications returns the connection back to the connection pool.1574* <p>1575* The pooling manager does not need to call {@code endRequest} if:1576* <ul>1577* <li>The connection pool caches {@code PooledConnection} objects</li>1578* <li>Returns a logical connection handle when {@code getConnection} is1579* called by the application</li>1580* <li>The logical {@code Connection} is closed by calling1581* {@code Connection.close} prior to returning the {@code PooledConnection}1582* to the cache.</li>1583* </ul>1584* @throws SQLException if an error occurs1585* @since 91586* @see beginRequest1587* @see javax.sql.PooledConnection1588*/1589default void endRequest() throws SQLException {1590// Default method takes no action1591}15921593/**1594* Sets and validates the sharding keys for this connection. A {@code null}1595* value may be specified for the sharding Key. The validity1596* of a {@code null} sharding key is vendor-specific. Consult your vendor's1597* documentation for additional information.1598* @implSpec1599* The default implementation will throw a1600* {@code SQLFeatureNotSupportedException}.1601*1602* @apiNote1603* This method validates that the sharding keys are valid for the1604* {@code Connection}. The timeout value indicates how long the driver1605* should wait for the {@code Connection} to verify that the sharding key1606* is valid before {@code setShardingKeyIfValid} returns false.1607* @param shardingKey the sharding key to be validated against this connection.1608* The sharding key may be {@code null}1609* @param superShardingKey the super sharding key to be validated against this1610* connection. The super sharding key may be {@code null}.1611* @param timeout time in seconds before which the validation process is expected to1612* be completed, otherwise the validation process is aborted. A value of 0 indicates1613* the validation process will not time out.1614* @return true if the connection is valid and the sharding keys are valid1615* and set on this connection; false if the sharding keys are not valid or1616* the timeout period expires before the operation completes.1617* @throws SQLException if an error occurs while performing this validation;1618* a {@code superSharedingKey} is specified1619* without a {@code shardingKey};1620* this method is called on a closed {@code connection}; or1621* the {@code timeout} value is negative.1622* @throws SQLFeatureNotSupportedException if the driver does not support sharding1623* @since 91624* @see ShardingKey1625* @see ShardingKeyBuilder1626*/1627default boolean setShardingKeyIfValid(ShardingKey shardingKey,1628ShardingKey superShardingKey, int timeout)1629throws SQLException {1630throw new SQLFeatureNotSupportedException("setShardingKeyIfValid not implemented");1631}16321633/**1634* Sets and validates the sharding key for this connection. A {@code null}1635* value may be specified for the sharding Key. The validity1636* of a {@code null} sharding key is vendor-specific. Consult your vendor's1637* documentation for additional information.1638* @implSpec1639* The default implementation will throw a1640* {@code SQLFeatureNotSupportedException}.1641* @apiNote1642* This method validates that the sharding key is valid for the1643* {@code Connection}. The timeout value indicates how long the driver1644* should wait for the {@code Connection} to verify that the sharding key1645* is valid before {@code setShardingKeyIfValid} returns false.1646* @param shardingKey the sharding key to be validated against this connection.1647* The sharding key may be {@code null}1648* @param timeout time in seconds before which the validation process is expected to1649* be completed,else the validation process is aborted. A value of 0 indicates1650* the validation process will not time out.1651* @return true if the connection is valid and the sharding key is valid to be1652* set on this connection; false if the sharding key is not valid or1653* the timeout period expires before the operation completes.1654* @throws SQLException if there is an error while performing this validation;1655* this method is called on a closed {@code connection};1656* or the {@code timeout} value is negative.1657* @throws SQLFeatureNotSupportedException if the driver does not support sharding1658* @since 91659* @see ShardingKey1660* @see ShardingKeyBuilder1661*/1662default boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout)1663throws SQLException {1664throw new SQLFeatureNotSupportedException("setShardingKeyIfValid not implemented");1665}16661667/**1668* Specifies a shardingKey and superShardingKey to use with this Connection1669* @implSpec1670* The default implementation will throw a1671* {@code SQLFeatureNotSupportedException}.1672* @apiNote1673* This method sets the specified sharding keys but does not require a1674* round trip to the database to validate that the sharding keys are valid1675* for the {@code Connection}.1676* @param shardingKey the sharding key to set on this connection. The sharding1677* key may be {@code null}1678* @param superShardingKey the super sharding key to set on this connection.1679* The super sharding key may be {@code null}1680* @throws SQLException if an error occurs setting the sharding keys;1681* this method is called on a closed {@code connection}; or1682* a {@code superSharedingKey} is specified without a {@code shardingKey}1683* @throws SQLFeatureNotSupportedException if the driver does not support sharding1684* @since 91685* @see ShardingKey1686* @see ShardingKeyBuilder1687*/1688default void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey)1689throws SQLException {1690throw new SQLFeatureNotSupportedException("setShardingKey not implemented");1691}16921693/**1694* Specifies a shardingKey to use with this Connection1695* @implSpec1696* The default implementation will throw a1697* {@code SQLFeatureNotSupportedException}.1698* @apiNote1699* This method sets the specified sharding key but does not require a1700* round trip to the database to validate that the sharding key is valid1701* for the {@code Connection}.1702* @param shardingKey the sharding key to set on this connection. The sharding1703* key may be {@code null}1704* @throws SQLException if an error occurs setting the sharding key; or1705* this method is called on a closed {@code connection}1706* @throws SQLFeatureNotSupportedException if the driver does not support sharding1707* @since 91708* @see ShardingKey1709* @see ShardingKeyBuilder1710*/1711default void setShardingKey(ShardingKey shardingKey)1712throws SQLException {1713throw new SQLFeatureNotSupportedException("setShardingKey not implemented");1714}1715}171617171718