A Connection represents a session with a specific
database. Within the context of a Connection, SQL statements are
executed and results are returned.
A Connection's database is able to provide information
describing its tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, etc. This
information is obtained with the getMetaData method.
Note: By default the Connection automatically commits
changes after executing each statement. If auto commit has been
disabled, an explicit commit must be done or database changes will
not be saved.
In some cases, it is desirable to immediately release a
Connection's database and JDBC resources instead of waiting for
them to be automatically released; the close method provides this
immediate release.
A Connection's database is able to provide information
describing its tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, etc.
A driver may convert the JDBC sql grammar into its system's
native SQL grammar prior to sending it; nativeSQL returns the
native form of the statement that the driver would have sent.
SQL statements without parameters are normally
executed using Statement objects. If the same SQL statement
is executed many times, it is more efficient to use a
PreparedStatement
A SQL statement with or without IN parameters can be
pre-compiled and stored in a PreparedStatement object. This
object can then be used to efficiently execute this statement
multiple times.
Note: This method is optimized for handling
parametric SQL statements that benefit from precompilation. If
the driver supports precompilation, prepareStatement will send
the statement to the database for precompilation. Some drivers
may not support precompilation. In this case, the statement may
not be sent to the database until the PreparedStatement is
executed. This has no direct affect on users; however, it does
affect which method throws certain SQLExceptions.
Parameters:
sql - a SQL statement that may contain one or more '?' IN
parameter placeholders
Returns:
a new PreparedStatement object containing the
pre-compiled statement
A SQL stored procedure call statement is handled by creating a
CallableStatement for it. The CallableStatement provides
methods for setting up its IN and OUT parameters, and
methods for executing it.
Note: This method is optimized for handling stored
procedure call statements. Some drivers may send the call
statement to the database when the prepareCall is done; others
may wait until the CallableStatement is executed. This has no
direct affect on users; however, it does affect which method
throws certain SQLExceptions.
Parameters:
sql - a SQL statement that may contain one or more '?'
parameter placeholders. Typically this statement is a JDBC
function call escape string.
Returns:
a new CallableStatement object containing the
pre-compiled SQL statement
A driver may convert the JDBC sql grammar into its system's
native SQL grammar prior to sending it; nativeSQL returns the
native form of the statement that the driver would have sent.
Parameters:
sql - a SQL statement that may contain one or more '?'
parameter placeholders
If a connection is in auto-commit mode, then all its SQL
statements will be executed and committed as individual
transactions. Otherwise, its SQL statements are grouped into
transactions that are terminated by either commit() or
rollback(). By default, new connections are in auto-commit
mode.
The commit occurs when the statement completes or the next
execute occurs, whichever comes first. In the case of
statements returning a ResultSet, the statement completes when
the last row of the ResultSet has been retrieved or the
ResultSet has been closed. In advanced cases, a single
statement may return multiple results as well as output
parameter values. Here the commit occurs when all results and
output param values have been retrieved.
Commit makes all changes made since the previous
commit/rollback permanent and releases any database locks
currently held by the Connection. This method should only be
used when auto commit has been disabled.
Rollback drops all changes made since the previous
commit/rollback and releases any database locks currently held
by the Connection. This method should only be used when auto
commit has been disabled.
In some cases, it is desirable to immediately release a
Connection's database and JDBC resources instead of waiting for
them to be automatically released; the close method provides this
immediate release.
Note: A Connection is automatically closed when it is
garbage collected. Certain fatal errors also result in a closed
Connection.
A Connection's database is able to provide information
describing its tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, etc. This
information is made available through a DatabaseMetaData
object.
A sub-space of this Connection's database may be selected by setting a
catalog name. If the driver does not support catalogs it will
silently ignore this request.