Build 1.0_r1(from source)

java.sql
Interface Connection


public interface Connection

A Connection represents a link from a Java application to a database. All SQL statements and results are returned within the context of a connection.


Field Summary
static int TRANSACTION_NONE
          A constant indicating that transactions are not supported.
static int TRANSACTION_READ_COMMITTED
          No dirty reads are permitted.
static int TRANSACTION_READ_UNCOMMITTED
          Dirty reads (reading from table rows containing changes that have not yet been committed), non-repeatable reads (reading table rows more than once in a transaction but getting back different data because other transactions may have altered rows between reads), and phantom reads (retrieving additional "phantom" rows in the course of repeated table reads because other transactions may have inserted additional rows that satisfy an SQL WHERE clause) are all permitted.
static int TRANSACTION_REPEATABLE_READ
          A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
static int TRANSACTION_SERIALIZABLE
          Dirty reads (reading from table rows containing changes that have not yet been committed), non-repeatable reads (reading table rows more than once in a transaction but getting back different data because other transactions may have altered rows between reads), and phantom reads (retrieving additional "phantom" rows in the course of repeated table reads because other transactions may have inserted additional rows that satisfy an SQL WHERE clause) are all prevented.
 
Method Summary
 void clearWarnings()
          Throws away any warnings that may have arisen for this connection.
 void close()
          Causes the instant release of all database and driver connection resources associated with this object.
 void commit()
          Commits all of the changes made subsequent to the last commit or rollback of the associated transaction.
 Statement createStatement()
          Returns a new instance of Statement for issuing SQL commands to the remote database.
 Statement createStatement(int resultSetType, int resultSetConcurrency)
          Returns a new instance of Statement whose associated ResultSets will have the characteristics specified in the type, concurrency and holdability arguments.
 Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Returns a new instance of Statement whose associated ResultSets will have the characteristics specified in the type, concurrency and holdability arguments.
 boolean getAutoCommit()
          Returns a boolean indication of whether or not this connection is in the auto-commit operating mode.
 String getCatalog()
          Gets this Connection object's current catalog name.
 int getHoldability()
          Returns the kind of holdability that any ResultSets made from this instance will have.
 DatabaseMetaData getMetaData()
          Gets the metadata about the database referenced by this connection.
 int getTransactionIsolation()
          Returns the present value of transaction isolation for this Connection instance.
 Map<String,Class<?>> getTypeMap()
          Returns the Type Map associated with this Connection object.
 SQLWarning getWarnings()
          Gets the first instance of any SQLWarning objects that may have been created in the use of this connection.
 boolean isClosed()
          Returns a boolean indication of whether or not this connection is in the closed state.
 boolean isReadOnly()
          Returns a boolean indication of whether or not this connection is currently in read-only state.
 String nativeSQL(String sql)
          Returns a string representation of the input SQL statement sql expressed in the underlying system's native SQL syntax.
 CallableStatement prepareCall(String sql)
          Returns a new instance of CallableStatement that may be used for making stored procedure calls to the database.
 CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
          Returns a new instance of CallableStatement that may be used for making stored procedure calls to the database.
 CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Returns a new instance of CallableStatement that may be used for making stored procedure calls to the database.
 PreparedStatement prepareStatement(String sql)
          Returns a new instance of PreparedStatement that may be used any number of times to execute parameterized requests on the database server.
 PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
          Creates a default PreparedStatement that can retrieve automatically generated keys.
 PreparedStatement prepareStatement(String sql, int[] columnIndexes)
          Creates a default PreparedStatement that can retrieve the auto-generated keys designated by a supplied array.
 PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
          Creates a PreparedStatement that generates ResultSets with the specified values of resultSetType and resultSetConcurrency.
 PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Creates a PreparedStatement that generates ResultSets with the specified type, concurrency and holdability
 PreparedStatement prepareStatement(String sql, String[] columnNames)
          Creates a default PreparedStatement that can retrieve the auto-generated keys designated by a supplied array.
 void releaseSavepoint(Savepoint savepoint)
          Releases savepoint from the present transaction.
 void rollback()
          Rolls back all updates made so far in this transaction as well as relinquishing all acquired database locks.
 void rollback(Savepoint savepoint)
          Undoes all changes made after the supplied Savepoint object was set.
 void setAutoCommit(boolean autoCommit)
          Sets this connection's auto-commit mode on or off.
 void setCatalog(String catalog)
          Sets the catalog name for this connection.
 void setHoldability(int holdability)
          Sets the holdability of ResultSets created by this Connection.
 void setReadOnly(boolean readOnly)
          Sets this connection to read-only mode.
 Savepoint setSavepoint()
          Creates an unnamed Savepoint in the current transaction.
 Savepoint setSavepoint(String name)
          Creates a named Savepoint in the current transaction.
 void setTransactionIsolation(int level)
          Sets the transaction isolation level for this Connection.
 void setTypeMap(Map<String,Class<?>> map)
          Sets the TypeMap for this connection.
 

Field Detail

TRANSACTION_NONE

static final int TRANSACTION_NONE
A constant indicating that transactions are not supported.

See Also:
Constant Field Values

TRANSACTION_READ_COMMITTED

static final int TRANSACTION_READ_COMMITTED
No dirty reads are permitted. Transactions may not read a row containing changes that have not yet been committed.

See Also:
Constant Field Values

TRANSACTION_READ_UNCOMMITTED

static final int TRANSACTION_READ_UNCOMMITTED
Dirty reads (reading from table rows containing changes that have not yet been committed), non-repeatable reads (reading table rows more than once in a transaction but getting back different data because other transactions may have altered rows between reads), and phantom reads (retrieving additional "phantom" rows in the course of repeated table reads because other transactions may have inserted additional rows that satisfy an SQL WHERE clause) are all permitted.

See Also:
Constant Field Values

TRANSACTION_REPEATABLE_READ

static final int TRANSACTION_REPEATABLE_READ
A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.

See Also:
Constant Field Values

TRANSACTION_SERIALIZABLE

static final int TRANSACTION_SERIALIZABLE
Dirty reads (reading from table rows containing changes that have not yet been committed), non-repeatable reads (reading table rows more than once in a transaction but getting back different data because other transactions may have altered rows between reads), and phantom reads (retrieving additional "phantom" rows in the course of repeated table reads because other transactions may have inserted additional rows that satisfy an SQL WHERE clause) are all prevented.

See Also:
Constant Field Values
Method Detail

clearWarnings

void clearWarnings()
                   throws SQLException
Throws away any warnings that may have arisen for this connection. Subsequent calls to getWarnings() will return null up until a brand new warning condition occurs.

Throws:
SQLException - if there is a problem accessing the database

close

void close()
           throws SQLException
Causes the instant release of all database and driver connection resources associated with this object. Any subsequent invocations of this method will have no effect.

It is strongly recommended that all Connections are closed before they are dereferenced by the application ready for garbage collection. While the finalize method of the Connection will close the Connection before garbage collection takes place, it is not advisable to leave the close operation to take place in this way. Unpredictable performance may result from closing Connections in the finalizer.

Throws:
SQLException - if there is a problem accessing the database

commit

void commit()
            throws SQLException
Commits all of the changes made subsequent to the last commit or rollback of the associated transaction. All locks in the database held by this connection are also relinquished. Calling this operation on connection objects in auto-commit mode is an error.

Throws:
SQLException - if there is a problem accessing the database or if the target connection instance is in auto-commit mode.

createStatement

Statement createStatement()
                          throws SQLException
Returns a new instance of Statement for issuing SQL commands to the remote database.

ResultSets generated by the returned Statement will default to type TYPE_FORWARD_ONLY and concurrency level CONCUR_READ_ONLY.

Returns:
a Statement object with default settings.
Throws:
SQLException - if there is a problem accessing the database

createStatement

Statement createStatement(int resultSetType,
                          int resultSetConcurrency)
                          throws SQLException
Returns a new instance of Statement whose associated ResultSets will have the characteristics specified in the type, concurrency and holdability arguments.

Parameters:
resultSetType - one of :
resultSetConcurrency - one of :
Returns:
a new instance of Statement capable of manufacturing ResultSets that satisfy the specified resultSetType and resultSetConcurrency values.
Throws:
SQLException - if there is a problem accessing the database

createStatement

Statement createStatement(int resultSetType,
                          int resultSetConcurrency,
                          int resultSetHoldability)
                          throws SQLException
Returns a new instance of Statement whose associated ResultSets will have the characteristics specified in the type, concurrency and holdability arguments.

Parameters:
resultSetType - one of :
resultSetConcurrency - one of :
resultSetHoldability - one of :
Returns:
a new instance of Statement capable of manufacturing ResultSets that satisfy the specified resultSetType, resultSetConcurrency and resultSetHoldability values.
Throws:
SQLException - if there is a problem accessing the database

getAutoCommit

boolean getAutoCommit()
                      throws SQLException
Returns a boolean indication of whether or not this connection is in the auto-commit operating mode.

Returns:
true if auto-commit is on, otherwise false
Throws:
SQLException - if there is a problem accessing the database

getCatalog

String getCatalog()
                  throws SQLException
Gets this Connection object's current catalog name.

Returns:
the catalog name. null if there is no catalog name.
Throws:
SQLException - if there is a problem accessing the database

getHoldability

int getHoldability()
                   throws SQLException
Returns the kind of holdability that any ResultSets made from this instance will have.

Returns:
one of :
Throws:
SQLException - if there is a problem accessing the a database

getMetaData

DatabaseMetaData getMetaData()
                             throws SQLException
Gets the metadata about the database referenced by this connection. The returned DatabaseMetaData describes the database topography, available stored procedures, SQL syntax and so on.

Returns:
a DatabaseMetaData object containing the database description
Throws:
SQLException - if there is a problem accessing the a database

getTransactionIsolation

int getTransactionIsolation()
                            throws SQLException
Returns the present value of transaction isolation for this Connection instance.

Returns:
the transaction isolation value
Throws:
SQLException - if there is a problem accessing the database
See Also:
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE

getTypeMap

Map<String,Class<?>> getTypeMap()
                                throws SQLException
Returns the Type Map associated with this Connection object. The type map will be empty unless the application has added at least one entry.

Returns:
the Type Map as a java.util.Map
Throws:
SQLException - if there is a problem accessing the database

getWarnings

SQLWarning getWarnings()
                       throws SQLException
Gets the first instance of any SQLWarning objects that may have been created in the use of this connection. If at least one warning has occurred then this operation returns the first one reported. A null indicates that no warnings have occurred.

By invoking the SQLWarning.getNextWarning() method of the returned SQLWarning object it is possible to obtain all warning objects.

Returns:
the first warning as an SQLWarning object (may be null)
Throws:
SQLException - if there is a problem accessing the database or if the call has been made on a connection which has been previously closed.

isClosed

boolean isClosed()
                 throws SQLException
Returns a boolean indication of whether or not this connection is in the closed state. The closed state may be entered into as a consequence of a successful invocation of the close() method or else if an error has occurred that prevents the connection from functioning normally.

Returns:
true if closed, otherwise false
Throws:
SQLException - if there is a problem accessing the database

isReadOnly

boolean isReadOnly()
                   throws SQLException
Returns a boolean indication of whether or not this connection is currently in read-only state.

Returns:
true if in read-only state, otherwise false.
Throws:
SQLException - if there is a problem accessing the database

nativeSQL

String nativeSQL(String sql)
                 throws SQLException
Returns a string representation of the input SQL statement sql expressed in the underlying system's native SQL syntax.

Parameters:
sql - the JDBC form of an SQL statement.
Returns:
the SQL statement in native database format.
Throws:
SQLException - if there is a problem accessing the database

prepareCall

CallableStatement prepareCall(String sql)
                              throws SQLException
Returns a new instance of CallableStatement that may be used for making stored procedure calls to the database.

Parameters:
sql - the SQL statement that calls the stored function
Returns:
a new instance of CallableStatement representing the SQL statement. ResultSets emitted from this CallableStatement will default to type ResultSet.TYPE_FORWARD_ONLY and concurrency ResultSet.CONCUR_READ_ONLY.
Throws:
SQLException - if a problem occurs accessing the database

prepareCall

CallableStatement prepareCall(String sql,
                              int resultSetType,
                              int resultSetConcurrency)
                              throws SQLException
Returns a new instance of CallableStatement that may be used for making stored procedure calls to the database. ResultSets emitted from this CallableStatement will satisfy the specified resultSetType and resultSetConcurrency values.

Parameters:
sql - the SQL statement
resultSetType - one of :
resultSetConcurrency - one of :
Returns:
a new instance of CallableStatement representing the precompiled SQL statement. ResultSets emitted from this CallableStatement will satisfy the specified resultSetType and resultSetConcurrency values.
Throws:
SQLException - if a problem occurs accessing the database

prepareCall

CallableStatement prepareCall(String sql,
                              int resultSetType,
                              int resultSetConcurrency,
                              int resultSetHoldability)
                              throws SQLException
Returns a new instance of CallableStatement that may be used for making stored procedure calls to the database. ResultSets created from this CallableStatement will have characteristics determined by the specified type, concurrency and holdability arguments.

Parameters:
sql - the SQL statement
resultSetType - one of :
resultSetConcurrency - one of :
resultSetHoldability - one of :
Returns:
a new instance of CallableStatement representing the precompiled SQL statement. ResultSets emitted from this CallableStatement will satisfy the specified resultSetType, resultSetConcurrency and resultSetHoldability values.
Throws:
SQLException - if a problem occurs accessing the database

prepareStatement

PreparedStatement prepareStatement(String sql)
                                   throws SQLException
Returns a new instance of PreparedStatement that may be used any number of times to execute parameterized requests on the database server.

Subject to JDBC driver support, this operation will attempt to send the precompiled version of the statement to the database. Alternatively, if the driver is not capable of flowing precompiled statements, the statement will not reach the database server until it is executed. This will have a bearing on precisely when SQLException instances get raised.

By default, ResultSets from the returned object will be ResultSet.TYPE_FORWARD_ONLY type with a ResultSet.CONCUR_READ_ONLY mode of concurrency.

Parameters:
sql - the SQL statement.
Returns:
the PreparedStatement containing the supplied SQL statement
Throws:
SQLException - if there is a problem accessing the database

prepareStatement

PreparedStatement prepareStatement(String sql,
                                   int autoGeneratedKeys)
                                   throws SQLException
Creates a default PreparedStatement that can retrieve automatically generated keys. Parameter autoGeneratedKeys may be used to specify to the driver if such keys should be made accessible. This is only the case when sql is an insert statement.

An SQL statement which may have IN parameters can be stored and precompiled in a PreparedStatement. The PreparedStatement can then be used to execute the statement multiple times in an efficient way.

Subject to JDBC driver support, this operation will attempt to send the precompiled version of the statement to the database. Alternatively, if the driver is not capable of flowing precompiled statements, the statement will not reach the database server until it is executed. This will have a bearing on precisely when SQLException instances get raised.

By default, ResultSets from the returned object will be ResultSet.TYPE_FORWARD_ONLY type with a ResultSet.CONCUR_READ_ONLY mode of concurrency.

Parameters:
sql - the SQL statement.
autoGeneratedKeys - one of :
Returns:
a new PreparedStatement instance representing the input SQL statement.
Throws:
SQLException - if there is a problem accessing the database

prepareStatement

PreparedStatement prepareStatement(String sql,
                                   int[] columnIndexes)
                                   throws SQLException
Creates a default PreparedStatement that can retrieve the auto-generated keys designated by a supplied array. If sql is an SQL INSERT statement, parameter columnIndexes is expected to hold the index values for each column in the statement's intended database table containing the autogenerated-keys of interest. Otherwise columnIndexes is ignored.

Subject to JDBC driver support, this operation will attempt to send the precompiled version of the statement to the database. Alternatively, if the driver is not capable of flowing precompiled statements, the statement will not reach the database server until it is executed. This will have a bearing on precisely when SQLException instances get raised.

By default, ResultSets from the returned object will be ResultSet.TYPE_FORWARD_ONLY type with a ResultSet.CONCUR_READ_ONLY mode of concurrency.

Parameters:
sql - the SQL statement.
columnIndexes - the indexes of the columns for which auto-generated keys should be made available.
Returns:
the PreparedStatement containing the supplied SQL statement
Throws:
SQLException - if a problem occurs accessing the database

prepareStatement

PreparedStatement prepareStatement(String sql,
                                   int resultSetType,
                                   int resultSetConcurrency)
                                   throws SQLException
Creates a PreparedStatement that generates ResultSets with the specified values of resultSetType and resultSetConcurrency.

Parameters:
sql - the SQL statement. It can contain one or more '?' IN parameter placeholders
resultSetType - one of :
resultSetConcurrency - one of :
Returns:
a new instance of PreparedStatement containing the SQL statement sql. ResultSets emitted from this PreparedStatement will satisfy the specified resultSetType and resultSetConcurrency values.
Throws:
SQLException - if a problem occurs accessing the database

prepareStatement

PreparedStatement prepareStatement(String sql,
                                   int resultSetType,
                                   int resultSetConcurrency,
                                   int resultSetHoldability)
                                   throws SQLException
Creates a PreparedStatement that generates ResultSets with the specified type, concurrency and holdability

Parameters:
sql - the SQL statement. It can contain one or more '?' IN parameter placeholders
resultSetType - one of :
resultSetConcurrency - one of :
resultSetHoldability - one of :
Returns:
a new instance of PreparedStatement containing the SQL statement sql. ResultSets emitted from this PreparedStatement will satisfy the specified resultSetType, resultSetConcurrency and resultSetHoldability values.
Throws:
SQLException - if a problem occurs accessing the database

prepareStatement

PreparedStatement prepareStatement(String sql,
                                   String[] columnNames)
                                   throws SQLException
Creates a default PreparedStatement that can retrieve the auto-generated keys designated by a supplied array. If sql is an SQL INSERT statement, columnNames is expected to hold the names of each column in the statement's associated database table containing the autogenerated-keys of interest. Otherwise columnNames is ignored.

Subject to JDBC driver support, this operation will attempt to send the precompiled version of the statement to the database. Alternatively, if the driver is not capable of flowing precompiled statements, the statement will not reach the database server until it is executed. This will have a bearing on precisely when SQLException instances get raised.

By default, ResultSets from the returned object will be ResultSet.TYPE_FORWARD_ONLY type with a ResultSet.CONCUR_READ_ONLY mode of concurrency.

Parameters:
sql - the SQL statement.
columnNames - the names of the columns for which auto-generated keys should be made available.
Returns:
the PreparedStatement containing the supplied SQL statement
Throws:
SQLException - if a problem occurs accessing the database

releaseSavepoint

void releaseSavepoint(Savepoint savepoint)
                      throws SQLException
Releases savepoint from the present transaction. Once removed, the Savepoint is considered invalid and should not be referenced further.

Parameters:
savepoint - the object targeted for removal
Throws:
SQLException - if there is a problem with accessing the database or if savepoint is considered not valid in this transaction.

rollback

void rollback()
              throws SQLException
Rolls back all updates made so far in this transaction as well as relinquishing all acquired database locks. It is an error to invoke this operation when in auto-commit mode.

Throws:
SQLException - if there is a problem with the database or if the method is called while in auto-commit mode of operation.

rollback

void rollback(Savepoint savepoint)
              throws SQLException
Undoes all changes made after the supplied Savepoint object was set. This method should only be used when auto-commit mode is disabled.

Parameters:
savepoint - the Savepoint to roll back to
Throws:
SQLException - if there is a problem accessing the database

setAutoCommit

void setAutoCommit(boolean autoCommit)
                   throws SQLException
Sets this connection's auto-commit mode on or off.

Putting a Connection into auto-commit mode means that all associated SQL statements will be run and committed in their own separate transactions. Alternatively, auto-commit set to off means that associated SQL statements get grouped into transactions that need to be completed by explicit calls to either the commit() or rollback() methods.

Auto-commit is the default mode for new connection instances.

When in this mode, commits will automatically occur upon successful SQL statement completion or upon successful completion of an execute. Statements are not considered successfully complete until all associated ResultSets and output parameters have been obtained or closed.

Calling this operation during an uncommitted transaction will result in it being committed.

Parameters:
autoCommit - boolean indication of whether to put the target connection into auto-commit mode (true) or not (false)
Throws:
SQLException - if there is a problem accessing the database

setCatalog

void setCatalog(String catalog)
                throws SQLException
Sets the catalog name for this connection. This is used to select a subspace of the database for future work. If the driver does not support catalog names, this method is ignored.

Parameters:
catalog - the catalog name to use.
Throws:
SQLException - if there is a problem accessing the database

setHoldability

void setHoldability(int holdability)
                    throws SQLException
Sets the holdability of ResultSets created by this Connection.

Parameters:
holdability - one of :
Throws:
SQLException - if there is a problem accessing the database

setReadOnly

void setReadOnly(boolean readOnly)
                 throws SQLException
Sets this connection to read-only mode.

This serves as a hint to the driver, which can enable database optimizations.

Parameters:
readOnly - true to set the Connection to read only mode. false disables read-only mode
Throws:
SQLException - if there is a problem accessing the database

setSavepoint

Savepoint setSavepoint()
                       throws SQLException
Creates an unnamed Savepoint in the current transaction.

Returns:
a Savepoint object for this savepoint.
Throws:
SQLException - if there is a problem accessing the database

setSavepoint

Savepoint setSavepoint(String name)
                       throws SQLException
Creates a named Savepoint in the current transaction.

Parameters:
name - the name to use for the new Savepoint.
Returns:
a Savepoint object for this savepoint.
Throws:
SQLException - if there is a problem accessing the database

setTransactionIsolation

void setTransactionIsolation(int level)
                             throws SQLException
Sets the transaction isolation level for this Connection.

If this method is called during a transaction, the results are implementation defined.

Parameters:
level - the new transaction isolation level to use from the following list of possible values :
Throws:
SQLException - if there is a problem with the database or if the value of level is not one of the expected constant values.

setTypeMap

void setTypeMap(Map<String,Class<?>> map)
                throws SQLException
Sets the TypeMap for this connection. The input map should contain mappings between complex Java and SQL types.

Parameters:
map - the new type map
Throws:
SQLException - if there is a problem accessing the database or if map is not an instance of Map.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature