Connection

public interface Connection implements Wrapper AutoCloseable

A connection (session) with a specific database. SQL statements are executed and results are returned within the context of a connection.

A Connection object's database is able to provide information describing its tables, its supported SQL grammar, its stored procedures, the capabilities of this connection, and so on. This information is obtained with the getMetaData method.

Note: When configuring a Connection, JDBC applications should use the appropriate Connection method such as setAutoCommit or setTransactionIsolation. Applications should not invoke SQL commands directly to change the connection's configuration when there is a JDBC method available. By default a Connection object is in auto-commit mode, which means that it automatically commits changes after executing each statement. If auto-commit mode has been disabled, the method commit must be called explicitly in order to commit changes; otherwise, database changes will not be saved.

A new Connection object created using the JDBC 2.1 core API has an initially empty type map associated with it. A user may enter a custom mapping for a UDT in this type map. When a UDT is retrieved from a data source with the method ResultSet.getObject, the getObject method will check the connection's type map to see if there is an entry for that UDT. If so, the getObject method will map the UDT to the class indicated. If there is no entry, the UDT will be mapped using the standard mapping.

A user may create a new type map, which is a java.util.Map object, make an entry in it, and pass it to the java.sql methods that can perform custom mapping. In this case, the method will use the given type map instead of the one associated with the connection.

For example, the following code fragment specifies that the SQL type ATHLETES will be mapped to the class Athletes in the Java programming language. The code fragment retrieves the type map for the Connection object con, inserts the entry into it, and then sets the type map with the new entry as the connection's type map.

      java.util.Map map = con.getTypeMap();
      map.put("mySchemaName.ATHLETES", Class.forName("Athletes"));
      con.setTypeMap(map);
 

Constant Summary

int TRANSACTION_NONE A constant indicating that transactions are not supported.
int TRANSACTION_READ_COMMITTED A constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur.
int TRANSACTION_READ_UNCOMMITTED A constant indicating that dirty reads, non-repeatable reads and phantom reads can occur.
int TRANSACTION_REPEATABLE_READ A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
int TRANSACTION_SERIALIZABLE A constant indicating that dirty reads, non-repeatable reads and phantom reads are prevented.

Public Method Summary

abstract void
clearWarnings()
Clears all warnings reported for this Connection object.
abstract void
close()
Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
abstract void
commit()
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this Connection object.
abstract Array
createArrayOf(String typeName, Object[] elements)
Factory method for creating Array objects.
abstract Blob
createBlob()
Constructs an object that implements the Blob interface.
abstract Clob
createClob()
Constructs an object that implements the Clob interface.
abstract NClob
createNClob()
Constructs an object that implements the NClob interface.
abstract SQLXML
createSQLXML()
Constructs an object that implements the SQLXML interface.
abstract Statement
createStatement(int resultSetType, int resultSetConcurrency)
Creates a Statement object that will generate ResultSet objects with the given type and concurrency.
abstract Statement
createStatement()
Creates a Statement object for sending SQL statements to the database.
abstract Statement
createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a Statement object that will generate ResultSet objects with the given type, concurrency, and holdability.
abstract Struct
createStruct(String typeName, Object[] attributes)
Factory method for creating Struct objects.
abstract boolean
getAutoCommit()
Retrieves the current auto-commit mode for this Connection object.
abstract String
getCatalog()
Retrieves this Connection object's current catalog name.
abstract String
getClientInfo(String name)
Returns the value of the client info property specified by name.
abstract Properties
getClientInfo()
Returns a list containing the name and current value of each client info property supported by the driver.
abstract int
getHoldability()
Retrieves the current holdability of ResultSet objects created using this Connection object.
abstract DatabaseMetaData
getMetaData()
Retrieves a DatabaseMetaData object that contains metadata about the database to which this Connection object represents a connection.
abstract int
getTransactionIsolation()
Retrieves this Connection object's current transaction isolation level.
abstract Map<StringClass<?>>
getTypeMap()
Retrieves the Map object associated with this Connection object.
abstract SQLWarning
getWarnings()
Retrieves the first warning reported by calls on this Connection object.
abstract boolean
isClosed()
Retrieves whether this Connection object has been closed.
abstract boolean
isReadOnly()
Retrieves whether this Connection object is in read-only mode.
abstract boolean
isValid(int timeout)
Returns true if the connection has not been closed and is still valid.
abstract String
nativeSQL(String sql)
Converts the given SQL statement into the system's native SQL grammar.
abstract CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency)
Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.
abstract CallableStatement
prepareCall(String sql)
Creates a CallableStatement object for calling database stored procedures.
abstract CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.
abstract PreparedStatement
prepareStatement(String sql, String[] columnNames)
Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.
abstract PreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.
abstract PreparedStatement
prepareStatement(String sql, int[] columnI