# Connection

Represents a connection (session) to a database.

Thread safety: the connection is thread-safe, because access is synchronized. However, for compatibility with other databases, a connection should only be used in one thread at any time.

Methods
void | abort(Executor executor) [Not supported]
void | abort(Executor executor) [Not supported] Parameters: executor - the executor used by this method
void | clearWarnings() Clears all warnings.
void | clearWarnings() throws SQLException Clears all warnings.
void | close() Closes this connection.
void | close() throws SQLException Closes this connection. All open statements, prepared statements and result sets that where created by this connection become invalid after calling this method. If there is an uncommitted transaction, it will be rolled back.
void | commit() Commits the current transaction.
void | commit() throws SQLException Commits the current transaction. This call has only an effect if auto commit is switched off. Throws: SQLException - if the connection is closed
Array | createArrayOf(String typeName, Object[] elements) [Not supported] Create a new empty Array object.
Array | createArrayOf(String typeName, Object[] elements) throws SQLException [Not supported] Create a new empty Array object.
Blob | createBlob() Create a new empty Blob object.
Blob | createBlob() throws SQLException Create a new empty Blob object. Returns: the object
Value | createBlob(InputStream x, long length) Create a Blob value from this input stream.
Value | createBlob(InputStream x, long length) Create a Blob value from this input stream. Parameters: x - the input stream length - the length (if smaller or equal than 0, all data until the end of file is read) Returns: the value
Clob | createClob() Create a new empty Clob object.
Clob | createClob() throws SQLException Create a new empty Clob object. Returns: the object
Value | createClob(Reader x, long length) Create a Clob value from this reader.
Value | createClob(Reader x, long length) Create a Clob value from this reader. Parameters: x - the reader length - the length (if smaller or equal than 0, all data until the end of file is read) Returns: the value
NClob | createNClob() Create a new empty NClob object.
NClob | createNClob() throws SQLException Create a new empty NClob object. Returns: the object
SQLXML | createSQLXML() [Not supported] Create a new empty SQLXML object.
SQLXML | createSQLXML() throws SQLException [Not supported] Create a new empty SQLXML object.
Statement | createStatement() Creates a new statement.
Statement | createStatement() throws SQLException Creates a new statement. Returns: the new statement Throws: SQLException - if the connection is closed
Statement | createStatement(int resultSetType, int resultSetConcurrency) Creates a statement with the specified result set type and concurrency.

Statement

createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
Creates a statement with the specified result set type and concurrency.
Parameters:
resultSetType - the result set type (ResultSet.TYPE_*)
resultSetConcurrency - the concurrency (ResultSet.CONCUR_*)
Returns:
the statement
Throws:
SQLException - if the connection is closed or the result set type or concurrency are not supported

Statement | createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a statement with the specified result set type, concurrency, and holdability.

Statement

createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates a statement with the specified result set type, concurrency, and holdability.
Parameters:
resultSetType - the result set type (ResultSet.TYPE_*)
resultSetConcurrency - the concurrency (ResultSet.CONCUR_*)
resultSetHoldability - the holdability (ResultSet.HOLD* / CLOSE*)
Returns:
the statement
Throws:
SQLException - if the connection is closed or the result set type, concurrency, or holdability are not supported

Struct | createStruct(String typeName, Object[] attributes) [Not supported] Create a new empty Struct object.
Struct | createStruct(String typeName, Object[] attributes) throws SQLException [Not supported] Create a new empty Struct object.
boolean | getAutoCommit() Gets the current setting for auto commit.
boolean | getAutoCommit() throws SQLException Gets the current setting for auto commit. Returns: true for on, false for off Throws: SQLException - if the connection is closed
String | getCatalog() Gets the current catalog name.
String | getCatalog() throws SQLException Gets the current catalog name. Returns: the catalog name Throws: SQLException - if the connection is closed
Properties | getClientInfo() Get the client properties.
Properties | getClientInfo() throws SQLException Get the client properties. Returns: the property list
String | getClientInfo(String name) Get a client property.
String | getClientInfo(String name) throws SQLException Get a client property. Parameters: name - the client info name (ignored) Returns: the property value
int | getHoldability() Returns the current result set holdability.
int | getHoldability() throws SQLException Returns the current result set holdability. Returns: the holdability Throws: SQLException - if the connection is closed
DatabaseMetaData | getMetaData() Gets the database meta data for this database.
DatabaseMetaData | getMetaData() throws SQLException Gets the database meta data for this database. Returns: the database meta data Throws: SQLException - if the connection is closed
int | getNetworkTimeout() [Not supported]
int | getNetworkTimeout() [Not supported]
String | getSchema() [Not supported]
String | getSchema() [Not supported]
int | getTransactionIsolation() Returns the current transaction isolation level.
int | getTransactionIsolation() throws SQLException Returns the current transaction isolation level. Returns: the isolation level. Throws: SQLException - if the connection is closed
Map | getTypeMap() Gets the type map.
Map | getTypeMap() throws SQLException Gets the type map. Returns: null Throws: SQLException - if the connection is closed
SQLWarning | getWarnings() Gets the first warning reported by calls on this object.
SQLWarning | getWarnings() throws SQLException Gets the first warning reported by calls on this object. Returns: null
boolean | isClosed() Returns true if this connection has been closed.
boolean | isClosed() throws SQLException Returns true if this connection has been closed. Returns: true if close was called
boolean | isReadOnly() Returns true if the database is read-only.
boolean | isReadOnly() throws SQLException Returns true if the database is read-only. Returns: if the database is read-only Throws: SQLException - if the connection is closed
boolean | isValid(int timeout) Returns true if this connection is still valid.
boolean | isValid(int timeout) Returns true if this connection is still valid. Parameters: timeout - the number of seconds to wait for the database to respond (ignored) Returns: true if the connection is valid.
boolean | isWrapperFor(Class iface) Checks if unwrap can return an object of this class.
boolean | isWrapperFor(Class iface) throws SQLException Checks if unwrap can return an object of this class. Parameters: iface - the class Returns: whether or not the interface is assignable from this class
String | nativeSQL(String sql) Translates a SQL statement into the database grammar.
String | nativeSQL(String sql) throws SQLException Translates a SQL statement into the database grammar. Parameters: sql - the SQL statement with or without JDBC escape sequences Returns: the translated statement Throws: SQLException - if the connection is closed
CallableStatement | prepareCall(String sql) Creates a new callable statement.
CallableStatement | prepareCall(String sql) throws SQLException Creates a new callable statement. Parameters: sql - the SQL statement Returns: the callable statement Throws: SQLException - if the connection is closed or the statement is not valid
CallableStatement | prepareCall(String sql, int resultSetType, int resultSetConcurrency) Creates a callable statement with the specified result set type and concurrency.

CallableStatement

prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates a callable statement with the specified result set type and concurrency.
Parameters:
sql - the SQL statement
resultSetType - the result set type (ResultSet.TYPE_*)
resultSetConcurrency - the concurrency (ResultSet.CONCUR_*)
Returns:
the callable statement
Throws:
SQLException - if the connection is closed or the result set type or concurrency are not supported

CallableStatement | prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a callable statement with the specified result set type, concurrency, and holdability.

CallableStatement

prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates a callable statement with the specified result set type, concurrency, and holdability.
Parameters:
sql - the SQL statement
resultSetType - the result set type (ResultSet.TYPE_*)
resultSetConcurrency - the concurrency (ResultSet.CONCUR_*)
resultSetHoldability - the holdability (ResultSet.HOLD* / CLOSE*)
Returns:
the callable statement
Throws:
SQLException - if the connection is closed or the result set type, concurrency, or holdability are not supported

PreparedStatement | prepareStatement(String sql) Creates a new prepared statement.
PreparedStatement | prepareStatement(String sql) throws SQLException Creates a new prepared statement. Parameters: sql - the SQL statement Returns: the prepared statement Throws: SQLException - if the connection is closed
PreparedStatement | prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Creates a prepared statement with the specified result set type and concurrency.

PreparedStatement

prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates a prepared statement with the specified result set type and concurrency.
Parameters:
sql - the SQL statement
resultSetType - the result set type (ResultSet.TYPE_*)
resultSetConcurrency - the concurrency (ResultSet.CONCUR_*)
Returns:
the prepared statement
Throws:
SQLException - if the connection is closed or the result set type or concurrency are not supported

PreparedStatement | prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a prepared statement with the specified result set type, concurrency, and holdability.

PreparedStatement

prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates a prepared statement with the specified result set type, concurrency, and holdability.
Parameters:
sql - the SQL statement
resultSetType - the result set type (ResultSet.TYPE_*)
resultSetConcurrency - the concurrency (ResultSet.CONCUR_*)
resultSetHoldability - the holdability (ResultSet.HOLD* / CLOSE*)
Returns:
the prepared statement
Throws:
SQLException - if the connection is closed or the result set type, concurrency, or holdability are not supported

PreparedStatement | prepareStatement(String sql, int autoGeneratedKeys) Creates a new prepared statement.
PreparedStatement | prepareStatement(String sql, int autoGeneratedKeys) throws SQLException Creates a new prepared statement. This method just calls prepareStatement(String sql) internally. The method getGeneratedKeys only supports one column. Parameters: sql - the SQL statement autoGeneratedKeys - ignored Returns: the prepared statement Throws: SQLException - if the connection is closed
PreparedStatement | prepareStatement(String sql, int[] columnIndexes) Creates a new prepared statement.
PreparedStatement | prepareStatement(String sql, int[] columnIndexes) throws SQLException Creates a new prepared statement. This method just calls prepareStatement(String sql) internally. The method getGeneratedKeys only supports one column. Parameters: sql - the SQL statement columnIndexes - ignored Returns: the prepared statement Throws: SQLException - if the connection is closed
PreparedStatement | prepareStatement(String sql, String[] columnNames) Creates a new prepared statement.
PreparedStatement | prepareStatement(String sql, String[] columnNames) throws SQLException Creates a new prepared statement. This method just calls prepareStatement(String sql) internally. The method getGeneratedKeys only supports one column. Parameters: sql - the SQL statement columnNames - ignored Returns: the prepared statement Throws: SQLException - if the connection is closed
void | releaseSavepoint(Savepoint savepoint) Releases a savepoint.
void | releaseSavepoint(Savepoint savepoint) throws SQLException Releases a savepoint. Parameters: savepoint - the savepoint to release
void | rollback() Rolls back the current transaction.
void | rollback() throws SQLException Rolls back the current transaction. This call has only an effect if auto commit is switched off. Throws: SQLException - if the connection is closed
void | rollback(Savepoint savepoint) Rolls back to a savepoint.
void | rollback(Savepoint savepoint) throws SQLException Rolls back to a savepoint. Parameters: savepoint - the savepoint
void | setAutoCommit(boolean autoCommit) Switches auto commit on or off.
void | setAutoCommit(boolean autoCommit) throws SQLException Switches auto commit on or off. Enabling it commits an uncommitted transaction, if there is one. Parameters: autoCommit - true for auto commit on, false for off Throws: SQLException - if the connection is closed
void | setCatalog(String catalog) Set the default catalog name.
void | setCatalog(String catalog) throws SQLException Set the default catalog name. This call is ignored. Parameters: catalog - ignored Throws: SQLException - if the connection is closed
void | setClientInfo(String name, String value) Set a client property.
void | setClientInfo(String name, String value) throws SQLClientInfoException Set a client property. This method always throws a SQLClientInfoException. Parameters: name - the name of the property (ignored) value - the value (ignored)
void | setClientInfo(Properties properties) Set the client properties.
void | setClientInfo(Properties properties) throws SQLClientInfoException Set the client properties. This method always throws a SQLClientInfoException. Parameters: properties - the properties (ignored)
void | setHoldability(int holdability) Changes the current result set holdability.
void | setHoldability(int holdability) throws SQLException Changes the current result set holdability. Parameters: holdability - ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT; Throws: SQLException - if the connection is closed or the holdability is not supported
void | setNetworkTimeout(Executor executor, int milliseconds) [Not supported]
void | setNetworkTimeout(Executor executor, int milliseconds) [Not supported] Parameters: executor - the executor used by this method milliseconds - the TCP connection timeout
void | setReadOnly(boolean readOnly) According to the JDBC specs, this setting is only a hint to the database to enable optimizations - it does not cause writes to be prohibited.
void | setReadOnly(boolean readOnly) throws SQLException According to the JDBC specs, this setting is only a hint to the database to enable optimizations - it does not cause writes to be prohibited. Parameters: readOnly - ignored Throws: SQLException - if the connection is closed
Savepoint | setSavepoint() Creates a new unnamed savepoint.
Savepoint | setSavepoint() throws SQLException Creates a new unnamed savepoint. Returns: the new savepoint
Savepoint | setSavepoint(String name) Creates a new named savepoint.
Savepoint | setSavepoint(String name) throws SQLException Creates a new named savepoint. Parameters: name - the savepoint name Returns: the new savepoint
void | setSchema(String schema) [Not supported]
void | setSchema(String schema) [Not supported] Parameters: schema - the schema
void | setTransactionIsolation(int level) Changes the current transaction isolation level.

void

setTransactionIsolation(int level) throws SQLException
Changes the current transaction isolation level. Calling this method will commit an open transaction, even if the new level is the same as the old one, except if the level is not supported. Internally, this method calls SET LOCK_MODE, which affects all connections. The following isolation levels are supported:

- Connection.TRANSACTION_READ_UNCOMMITTED = SET LOCK_MODE 0: no locking (should only be used for testing).
- Connection.TRANSACTION_SERIALIZABLE = SET LOCK_MODE 1: table level locking.
- Connection.TRANSACTION_READ_COMMITTED = SET LOCK_MODE 3: table level locking, but read locks are released immediately (default).

This setting is not persistent. Please note that using TRANSACTION_READ_UNCOMMITTED while at the same time using multiple connections may result in inconsistent transactions.
Parameters:
level - the new transaction isolation level: Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, or Connection.TRANSACTION_SERIALIZABLE
Throws:
SQLException - if the connection is closed or the isolation level is not supported

void | setTypeMap(Map map) [Partially supported] Sets the type map.
void | setTypeMap(Map map) throws SQLException [Partially supported] Sets the type map. This is only supported if the map is empty or null.
T | unwrap(Class iface) Return an object of this class if possible.
T | unwrap(Class iface) throws SQLException Return an object of this class if possible. Parameters: iface - the class Returns: this