| java.sql.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.
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | TRANSACTION_NONE | A constant indicating that transactions are not supported. | |||||||||
| int | TRANSACTION_READ_COMMITTED | No dirty reads are permitted. | |||||||||
| 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. |
|||||||||
| int | TRANSACTION_REPEATABLE_READ | A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur. | |||||||||
| 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. |
|||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Throws away any warnings that may have arisen for this connection.
| |||||||||||
Causes the instant release of all database and driver connection
resources associated with this object.
| |||||||||||
Commits all of the changes made subsequent to the last commit or rollback
of the associated transaction.
| |||||||||||
Returns a new instance of
Statement whose associated
ResultSets will have the characteristics specified in the
type, concurrency and holdability arguments. | |||||||||||
Returns a new instance of
Statement whose associated
ResultSets will have the characteristics specified in the
type, concurrency and holdability arguments. | |||||||||||
Returns a new instance of
Statement for issuing SQL
commands to the remote database. | |||||||||||
Returns a boolean indication of whether or not this connection is in the
auto-commit operating mode.
| |||||||||||
Gets this Connection object's current catalog name.
| |||||||||||
Returns the kind of holdability that any
ResultSets made
from this instance will have. | |||||||||||
Gets the metadata about the database referenced by this connection.
| |||||||||||
Returns the present value of transaction isolation for this Connection
instance.
| |||||||||||
Returns the Type Map associated with this Connection object.
| |||||||||||
Gets the first instance of any
SQLWarning objects that may
have been created in the use of this connection. | |||||||||||
Returns a boolean indication of whether or not this connection is in the
closed state.
| |||||||||||
Returns a boolean indication of whether or not this connection is
currently in read-only state.
| |||||||||||
Returns a string representation of the input SQL statement
sql expressed in the underlying system's native SQL
syntax. | |||||||||||
Returns a new instance of
CallableStatement that may be
used for making stored procedure calls to the database. | |||||||||||
Returns a new instance of
CallableStatement that may be
used for making stored procedure calls to the database. | |||||||||||
Returns a new instance of
CallableStatement that may be
used for making stored procedure calls to the database. | |||||||||||
Creates a default PreparedStatement that can retrieve automatically
generated keys.
| |||||||||||
Creates a default PreparedStatement that can retrieve the auto-generated
keys designated by a supplied array.
| |||||||||||
Creates a PreparedStatement that generates ResultSets with the specified
type, concurrency and holdability
| |||||||||||
Creates a PreparedStatement that generates ResultSets with the specified
values of
resultSetType and
resultSetConcurrency. | |||||||||||
Returns a new instance of
PreparedStatement that may be
used any number of times to execute parameterized requests on the
database server. | |||||||||||
Creates a default PreparedStatement that can retrieve the auto-generated
keys designated by a supplied array.
| |||||||||||
Releases
savepoint from the present transaction. | |||||||||||
Undoes all changes made after the supplied Savepoint object was set.
| |||||||||||
Rolls back all updates made so far in this transaction as well as
relinquishing all acquired database locks.
| |||||||||||
Sets this connection's auto-commit mode on or off.
| |||||||||||
Sets the catalog name for this connection.
| |||||||||||
Sets the holdability of ResultSets created by this Connection.
| |||||||||||
Sets this connection to read-only mode.
| |||||||||||
Creates an unnamed Savepoint in the current transaction.
| |||||||||||
Creates a named Savepoint in the current transaction.
| |||||||||||
Sets the transaction isolation level for this Connection.
| |||||||||||
Sets the
TypeMap for this connection. | |||||||||||
A constant indicating that transactions are not supported.
No dirty reads are permitted. Transactions may not read a row containing changes that have not yet been committed.
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.
A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
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.
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.
| SQLException | if there is a problem accessing the database |
|---|
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.
| SQLException | if there is a problem accessing the database |
|---|
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.
| SQLException | if there is a problem accessing the database or if the target connection instance is in auto-commit mode. |
|---|
Returns a new instance of Statement whose associated
ResultSets will have the characteristics specified in the
type, concurrency and holdability arguments.
| resultSetType | one of : |
|---|---|
| resultSetConcurrency | one of : |
| resultSetHoldability | one of : |
Statement capable of
manufacturing ResultSets that satisfy the
specified resultSetType,
resultSetConcurrency and
resultSetHoldability values.| SQLException | if there is a problem accessing the database |
|---|
Returns a new instance of Statement whose associated
ResultSets will have the characteristics specified in the
type, concurrency and holdability arguments.
| resultSetType | one of : |
|---|---|
| resultSetConcurrency | one of : |
Statement capable of
manufacturing ResultSets that satisfy the
specified resultSetType and
resultSetConcurrency values.| SQLException | if there is a problem accessing the database |
|---|
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.
Statement object with default settings.| SQLException | if there is a problem accessing the database |
|---|
Returns a boolean indication of whether or not this connection is in the auto-commit operating mode.
true if auto-commit is on, otherwise
false| SQLException | if there is a problem accessing the database |
|---|
Gets this Connection object's current catalog name.
null if there is no catalog
name.| SQLException | if there is a problem accessing the database |
|---|
Returns the kind of holdability that any ResultSets made
from this instance will have.
| SQLException | if there is a problem accessing the a database |
|---|
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.
DatabaseMetaData object containing the database
description| SQLException | if there is a problem accessing the a database |
|---|
Returns the present value of transaction isolation for this Connection instance.
| SQLException | if there is a problem accessing the database |
|---|
Returns the Type Map associated with this Connection object. The type map will be empty unless the application has added at least one entry.
java.util.Map| SQLException | if there is a problem accessing the database |
|---|
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 getNextWarning() method of the
returned SQLWarning object it is possible to obtain all
warning objects.
null)| SQLException | if there is a problem accessing the database or if the call has been made on a connection which has been previously closed. |
|---|
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.
true if closed, otherwise false| SQLException | if there is a problem accessing the database |
|---|
Returns a boolean indication of whether or not this connection is currently in read-only state.
true if in read-only state, otherwise
false.| SQLException | if there is a problem accessing the database |
|---|
Returns a string representation of the input SQL statement
sql expressed in the underlying system's native SQL
syntax.
| sql | the JDBC form of an SQL statement. |
|---|
| SQLException | if there is a problem accessing the database |
|---|
Returns a new instance of CallableStatement that may be
used for making stored procedure calls to the database.
| sql | the SQL statement that calls the stored function |
|---|
CallableStatement representing
the SQL statement. ResultSets emitted from this
CallableStatement will default to type
TYPE_FORWARD_ONLY and concurrency
CONCUR_READ_ONLY.| SQLException | if a problem occurs accessing the database |
|---|
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.
| sql | the SQL statement |
|---|---|
| resultSetType | one of : |
| resultSetConcurrency | one of : |
| resultSetHoldability | one of : |
CallableStatement representing
the precompiled SQL statement. ResultSets emitted
from this CallableStatement will satisfy the
specified resultSetType,
resultSetConcurrency and
resultSetHoldability values.| SQLException | if a problem occurs accessing the database |
|---|
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.
| sql | the SQL statement |
|---|---|
| resultSetType | one of : |
| resultSetConcurrency | one of : |
CallableStatement representing
the precompiled SQL statement. ResultSets emitted
from this CallableStatement will satisfy the
specified resultSetType and
resultSetConcurrency values.| SQLException | if a problem occurs accessing the database |
|---|
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 TYPE_FORWARD_ONLY type with a CONCUR_READ_ONLY mode of concurrency.
| sql | the SQL statement. |
|---|---|
| autoGeneratedKeys | one of : |
PreparedStatement instance representing the
input SQL statement.| SQLException | if there is a problem accessing the database |
|---|
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 TYPE_FORWARD_ONLY type with a CONCUR_READ_ONLY mode of concurrency.
| sql | the SQL statement. |
|---|---|
| columnNames | the names of the columns for which auto-generated keys should be made available. |
| SQLException | if a problem occurs accessing the database |
|---|
Creates a PreparedStatement that generates ResultSets with the specified type, concurrency and holdability
| sql | the SQL statement. It can contain one or more '?' IN parameter placeholders |
|---|---|
| resultSetType | one of : |
| resultSetConcurrency | one of : |
| resultSetHoldability | one of : |
PreparedStatement containing the
SQL statement sql. ResultSets
emitted from this PreparedStatement will satisfy
the specified resultSetType,
resultSetConcurrency and
resultSetHoldability values.| SQLException | if a problem occurs accessing the database |
|---|
Creates a PreparedStatement that generates ResultSets with the specified
values of resultSetType and
resultSetConcurrency.
| sql | the SQL statement. It can contain one or more '?' IN parameter placeholders |
|---|---|
| resultSetType | one of : |
| resultSetConcurrency | one of : |
PreparedStatement containing the
SQL statement sql. ResultSets
emitted from this PreparedStatement will satisfy
the specified resultSetType and
resultSetConcurrency values.| SQLException | if a problem occurs accessing the database |
|---|
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 TYPE_FORWARD_ONLY type with a CONCUR_READ_ONLY mode of concurrency.
| sql | the SQL statement. |
|---|
| SQLException | if there is a problem accessing the database |
|---|
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 TYPE_FORWARD_ONLY type with a CONCUR_READ_ONLY mode of concurrency.
| sql | the SQL statement. |
|---|---|
| columnIndexes | the indexes of the columns for which auto-generated keys should be made available. |
| SQLException | if a problem occurs accessing the database |
|---|
Releases savepoint from the present transaction. Once
removed, the Savepoint is considered invalid and should
not be referenced further.
| savepoint | the object targeted for removal |
|---|
| SQLException | if there is a problem with accessing the database or if
savepoint is considered not valid in this
transaction.
|
|---|
Undoes all changes made after the supplied Savepoint object was set. This method should only be used when auto-commit mode is disabled.
| savepoint | the Savepoint to roll back to |
|---|
| SQLException | if there is a problem accessing the database |
|---|
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.
| SQLException | if there is a problem with the database or if the method is called while in auto-commit mode of operation. |
|---|
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.
| autoCommit | boolean indication of whether to put the target connection
into auto-commit mode (true) or not (false) |
|---|
| SQLException | if there is a problem accessing the database |
|---|
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.
| catalog | the catalog name to use. |
|---|
| SQLException | if there is a problem accessing the database |
|---|
Sets the holdability of ResultSets created by this Connection.
| holdability | one of : |
|---|
| SQLException | if there is a problem accessing the database |
|---|
Sets this connection to read-only mode.
This serves as a hint to the driver, which can enable database optimizations.
| readOnly | true to set the Connection to read only mode. false disables read-only mode |
|---|
| SQLException | if there is a problem accessing the database |
|---|
Creates an unnamed Savepoint in the current transaction.
| SQLException | if there is a problem accessing the database |
|---|
Creates a named Savepoint in the current transaction.
| name | the name to use for the new Savepoint. |
|---|
| SQLException | if there is a problem accessing the database |
|---|
Sets the transaction isolation level for this Connection.
If this method is called during a transaction, the results are implementation defined.
| level | the new transaction isolation level to use from the following list of possible values : |
|---|
| SQLException | if there is a problem with the database or if the value of
level is not one of the expected constant
values.
|
|---|
Sets the TypeMap for this connection. The input
map should contain mappings between complex Java and SQL
types.
| map | the new type map |
|---|
| SQLException | if there is a problem accessing the database or if
map is not an instance of Map.
|
|---|