Connection

Represents a connection (session) to a database.

Methods
void clearWarnings()
Clears all warnings.
void close()
Closes this connection.
void commit()
Commits the current transaction.
Blob createBlob()
Create a new empty Blob object.
Clob createClob()
Create a new empty Clob object.
Statement createStatement()
Creates a new statement.
Statement createStatement(int resultSetType, int resultSetConcurrency)
Creates a statement with the specified result set type and concurrency.
Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a statement with the specified result set type, concurrency, and holdability.
boolean getAutoCommit()
Gets the current setting for auto commit.
String getCatalog()
Gets the current catalog name.
int getHoldability()
Returns the current result set holdability.
DatabaseMetaData getMetaData()
Gets the database meta data for this database.
int getTransactionIsolation()
Returns the current transaction isolation level.
Map getTypeMap()
Gets the type map.
SQLWarning getWarnings()
Gets the first warning reported by calls on this object.
boolean isClosed()
Returns true if this connection has been closed.
boolean isReadOnly()
Returns true if the database is read-only.
boolean isValid(int timeout)
Returns true if this connection is still valid.
String nativeSQL(String sql)
Translates a SQL statement into the database grammar.
CallableStatement prepareCall(String sql)
Creates a new callable statement.
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, int resultSetHoldability)
Creates a callable statement with the specified result set type, concurrency, and holdability.
PreparedStatement prepareStatement(String sql)
Creates a new prepared statement.
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, int resultSetHoldability)
Creates a prepared statement with the specified result set type, concurrency, and holdability.
PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
Creates a new prepared statement.
PreparedStatement prepareStatement(String sql, int[] columnIndexes)
Creates a new prepared statement.
PreparedStatement prepareStatement(String sql, String[] columnNames)
Creates a new prepared statement.
void releaseSavepoint(Savepoint savepoint)
Releases a savepoint.
void rollback()
Rolls back the current transaction.
void rollback(Savepoint savepoint)
Rolls back to a savepoint.
void setAutoCommit(boolean autoCommit)
Switches auto commit on or off.
void setCatalog(String catalog)
Set the default catalog name.
void setHoldability(int holdability)
Changes the current result set holdability.
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.
Savepoint setSavepoint()
Creates a new unnamed savepoint.
Savepoint setSavepoint(String name)
Creates a new named savepoint.
void setTransactionIsolation(int level)
Changes the current transaction isolation level.
void setTypeMap(Map map)
[Partially supported] Sets the type map.

void clearWarnings() throws SQLException

Clears all warnings.

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() 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

Blob createBlob() throws SQLException

Create a new empty Blob object.

Returns:
the object

Clob createClob() throws SQLException

Create a new empty Clob object.

Returns:
the object

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) throws SQLException

Creates a statement with the specified result set type and concurrency.

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) throws SQLException

Creates a statement with the specified result set type, concurrency, and holdability.

Returns:
the statement
Throws:
SQLException - if the connection is closed or the result set type, concurrency, or holdability are not supported

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() throws SQLException

Gets the current catalog name.

Throws:
SQLException - if the connection is closed

int getHoldability() throws SQLException

Returns the current result set holdability.

Returns:
the holdability
Throws:
SQLException - if the connection is closed

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 getTransactionIsolation() throws SQLException

Returns the current transaction isolation level.

Returns:
the isolation level.
Throws:
SQLException - if the connection is closed

Map getTypeMap() throws SQLException

Gets the type map.

Returns:
null
Throws:
SQLException - if the connection is closed

SQLWarning getWarnings() throws SQLException

Gets the first warning reported by calls on this object.

Returns:
null

boolean isClosed() throws SQLException

Returns true if this connection has been closed.

Returns:
true if close was called

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.

Returns:
true if the connection is valid.

String nativeSQL(String sql) throws SQLException

Translates a SQL statement into the database grammar.

Returns:
the translated statement
Throws:
SQLException - if the connection is closed

CallableStatement prepareCall(String sql) throws SQLException

Creates a new callable 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) throws SQLException

Creates a callable statement with the specified result set type and concurrency.

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) throws SQLException

Creates a callable statement with the specified result set type, concurrency, and holdability.

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) throws SQLException

Creates a new prepared statement.

Returns:
the prepared statement
Throws:
SQLException - if the connection is closed

PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException

Creates a prepared statement with the specified result set type and concurrency.

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) throws SQLException

Creates a prepared statement with the specified result set type, concurrency, and holdability.

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) throws SQLException

Creates a new prepared statement. This method just calls prepareStatement(String sql).

Returns:
the prepared statement
Throws:
SQLException - if the connection is closed

PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException

Creates a new prepared statement. This method just calls prepareStatement(String sql).

Returns:
the prepared statement
Throws:
SQLException - if the connection is closed

PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException

Creates a new prepared statement. This method just calls prepareStatement(String sql).

Returns:
the prepared statement
Throws:
SQLException - if the connection is closed

void releaseSavepoint(Savepoint savepoint) throws SQLException

Releases a savepoint.

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) throws SQLException

Rolls back to a savepoint.

void setAutoCommit(boolean autoCommit) throws SQLException

Switches auto commit on or off. Calling this function does not commit the current transaction.

Parameters:
autoCommit - true for auto commit on, false for off
Throws:
SQLException - if the connection is closed

void setCatalog(String catalog) throws SQLException

Set the default catalog name. This call is ignored.

Throws:
SQLException - if the connection is closed

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 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.

Throws:
SQLException - if the connection is closed

Savepoint setSavepoint() throws SQLException

Creates a new unnamed savepoint.

Returns:
the new savepoint

Savepoint setSavepoint(String name) throws SQLException

Creates a new named savepoint.

Returns:
the new savepoint

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. 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) throws SQLException

[Partially supported] Sets the type map. This is only supported if the map is empty or null.