GeezerVison is showing docs.oracle.com — Connection (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact2, compact3
java.sql
Interface Connection
-
-
Field Summary
Fields
| Modifier and Type |
Field |
Description |
static int |
TRANSACTION_NONE |
A constant indicating that transactions are not supported.
|
static int |
TRANSACTION_READ_COMMITTED |
A constant indicating that
dirty reads are prevented; non-repeatable reads and phantom
reads can occur.
|
static int |
TRANSACTION_READ_UNCOMMITTED |
A constant indicating that
dirty reads, non-repeatable reads and phantom reads can occur.
|
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 |
A constant indicating that
dirty reads, non-repeatable reads and phantom reads are prevented.
|
-
Method Summary
All Methods Instance Methods Abstract Methods
| Modifier and Type |
Method |
Description |
void |
abort(Executor executor) |
Terminates an open connection.
|
void |
clearWarnings() |
Clears all warnings reported for this Connection object.
|
void |
close() |
Releases this Connection object's database and JDBC resources
immediately instead of waiting for them to be automatically released.
|
void |
commit() |
Makes all changes made since the previous
commit/rollback permanent and releases any database locks
currently held by this Connection object.
|
Array |
createArrayOf(String typeName,
Object[] elements) |
Factory method for creating Array objects.
|
Blob |
createBlob() |
Constructs an object that implements the Blob interface.
|
Clob |
createClob() |
Constructs an object that implements the Clob interface.
|
NClob |
createNClob() |
Constructs an object that implements the NClob interface.
|
SQLXML |
createSQLXML() |
Constructs an object that implements the SQLXML interface.
|
Statement |
createStatement() |
Creates a Statement object for sending
SQL statements to the database.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency) |
Creates a Statement object that will generate
ResultSet objects with the given type and concurrency.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
Creates a Statement object that will generate
ResultSet objects with the given type, concurrency,
and holdability.
|
Struct |
createStruct(String typeName,
Object[] attributes) |
Factory method for creating Struct objects.
|
boolean |
getAutoCommit() |
Retrieves the current auto-commit mode for this Connection
object.
|
String |
getCatalog() |
Retrieves this Connection object's current catalog name.
|
Properties |
getClientInfo() |
Returns a list containing the name and current value of each client info
property supported by the driver.
|
String |
getClientInfo(String name) |
Returns the value of the client info property specified by name.
|
int |
getHoldability() |
Retrieves the current holdability of ResultSet objects
created using this Connection object.
|
DatabaseMetaData |
getMetaData() |
Retrieves a DatabaseMetaData object that contains
metadata about the database to which this
Connection object represents a connection.
|
int |
getNetworkTimeout() |
Retrieves the number of milliseconds the driver will
wait for a database request to complete.
|
String |
getSchema() |
Retrieves this Connection object's current schema name.
|
int |
getTransactionIsolation() |
Retrieves this Connection object's current
transaction isolation level.
|
Map<String,Class<?>> |
getTypeMap() |
Retrieves the Map object associated with this
Connection object.
|
SQLWarning |
getWarnings() |
Retrieves the first warning reported by calls on this
Connection object.
|
boolean |
isClosed() |
Retrieves whether this Connection object has been
closed.
|
boolean |
isReadOnly() |
Retrieves whether this Connection
object is in read-only mode.
|
boolean |
isValid(int timeout) |
Returns true if the connection has not been closed and is still valid.
|
String |
nativeSQL(String sql) |
Converts the given SQL statement into the system's native SQL grammar.
|
CallableStatement |
prepareCall(String sql) |
Creates a CallableStatement object for calling
database stored procedures.
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency) |
Creates a CallableStatement object that will generate
ResultSet objects with the given type and concurrency.
|
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.
|
PreparedStatement |
prepareStatement(String sql) |
Creates a PreparedStatement object for sending
parameterized SQL statements to the database.
|
PreparedStatement |
prepareStatement(String sql,
int autoGeneratedKeys) |
Creates a default PreparedStatement object that has
the capability to retrieve auto-generated keys.
|
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes) |
Creates a default PreparedStatement object capable
of returning the auto-generated keys designated by the given array.
|
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency) |
Creates a PreparedStatement object that will generate
ResultSet objects with the given type and concurrency.
|
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.
|
PreparedStatement |
prepareStatement(String sql,
String[] columnNames) |
Creates a default PreparedStatement object capable
of returning the auto-generated keys designated by the given array.
|
void |
releaseSavepoint(Savepoint savepoint) |
Removes the specified Savepoint and subsequent Savepoint objects from the current
transaction.
|
void |
rollback() |
Undoes all changes made in the current transaction
and releases any database locks currently held
by this Connection object.
|
void |
rollback(Savepoint savepoint) |
Undoes all changes made after the given Savepoint object
was set.
|
void |
setAutoCommit(boolean autoCommit) |
Sets this connection's auto-commit mode to the given state.
|
void |
setCatalog(String catalog) |
Sets the given catalog name in order to select
a subspace of this Connection object's database
in which to work.
|
void |
setClientInfo(Properties properties) |
Sets the value of the connection's client info properties.
|
void |
setClientInfo(String name,
String value) |
Sets the value of the client info property specified by name to the
value specified by value.
|
void |
setHoldability(int holdability) |
Changes the default holdability of ResultSet objects
created using this Connection object to the given
holdability.
|
void |
setNetworkTimeout(Executor executor,
int milliseconds) |
Sets the maximum period a Connection or
objects created from the Connection
will wait for the database to reply to any one request.
|
void |
setReadOnly(boolean readOnly) |
Puts this connection in read-only mode as a hint to the driver to enable
database optimizations.
|
Savepoint |
setSavepoint() |
Creates an unnamed savepoint in the current transaction and
returns the new Savepoint object that represents it.
|
Savepoint |
setSavepoint(String name) |
Creates a savepoint with the given name in the current transaction
and returns the new Savepoint object that represents it.
|
void |
setSchema(String schema) |
Sets the given schema name to access.
|
void |
setTransactionIsolation(int level) |
Attempts to change the transaction isolation level for this
Connection object to the one given.
|
void |
setTypeMap(Map<String,Class<?>> map) |
Installs the given TypeMap object as the type map for
this Connection object.
|
-
-
Field Detail
-
TRANSACTION_READ_UNCOMMITTED
static final int TRANSACTION_READ_UNCOMMITTED
A constant indicating that
dirty reads, non-repeatable reads and phantom reads can occur.
This level allows a row changed by one transaction to be read
by another transaction before any changes in that row have been
committed (a "dirty read"). If any of the changes are rolled back,
the second transaction will have retrieved an invalid row.
- See Also:
- Constant Field Values
-
TRANSACTION_READ_COMMITTED
static final int TRANSACTION_READ_COMMITTED
A constant indicating that
dirty reads are prevented; non-repeatable reads and phantom
reads can occur. This level only prohibits a transaction
from reading a row with uncommitted changes in it.
- 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. This level prohibits a transaction from
reading a row with uncommitted changes in it, and it also
prohibits the situation where one transaction reads a row,
a second transaction alters the row, and the first transaction
rereads the row, getting different values the second time
(a "non-repeatable read").
- See Also:
- Constant Field Values
-
TRANSACTION_SERIALIZABLE
static final int TRANSACTION_SERIALIZABLE
A constant indicating that
dirty reads, non-repeatable reads and phantom reads are prevented.
This level includes the prohibitions in
TRANSACTION_REPEATABLE_READ and further prohibits the
situation where one transaction reads all rows that satisfy
a WHERE condition, a second transaction inserts a row that
satisfies that WHERE condition, and the first transaction
rereads for the same condition, retrieving the additional
"phantom" row in the second read.
- See Also:
- Constant Field Values
-
Method Detail
-
nativeSQL
String nativeSQL(String sql)
throws SQLException
Converts the given SQL statement into the system's native SQL grammar.
A driver may convert the JDBC SQL grammar into its system's
native SQL grammar prior to sending it. This method returns the
native form of the statement that the driver would have sent.
- Parameters:
sql - an SQL statement that may contain one or more '?'
parameter placeholders
- Returns:
- the native form of this statement
- Throws:
SQLException - if a database access error occurs
or this method is called on a closed connection
-
commit
void commit()
throws SQLException
Makes all changes made since the previous
commit/rollback permanent and releases any database locks
currently held by this Connection object.
This method should be
used only when auto-commit mode has been disabled.
- Throws:
SQLException - if a database access error occurs,
this method is called while participating in a distributed transaction,
if this method is called on a closed connection or this
Connection object is in auto-commit mode
- See Also:
setAutoCommit(boolean)
-
rollback
void rollback()
throws SQLException
Undoes all changes made in the current transaction
and releases any database locks currently held
by this Connection object. This method should be
used only when auto-commit mode has been disabled.
- Throws:
SQLException - if a database access error occurs,
this method is called while participating in a distributed transaction,
this method is called on a closed connection or this
Connection object is in auto-commit mode
- See Also:
setAutoCommit(boolean)
-
getMetaData
DatabaseMetaData getMetaData()
throws SQLException
Retrieves a DatabaseMetaData object that contains
metadata about the database to which this
Connection object represents a connection.
The metadata includes information about the database's
tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, and so on.
- Returns:
- a
DatabaseMetaData object for this
Connection object
- Throws:
SQLException - if a database access error occurs
or this method is called on a closed connection
-
clearWarnings
void clearWarnings()
throws SQLException
Clears all warnings reported for this Connection object.
After a call to this method, the method getWarnings
returns null until a new warning is
reported for this Connection object.
- Throws:
SQLException - SQLException if a database access error occurs
or this method is called on a closed connection
-
releaseSavepoint
void releaseSavepoint(Savepoint savepoint)
throws SQLException
Removes the specified Savepoint and subsequent Savepoint objects from the current
transaction. Any reference to the savepoint after it have been removed
will cause an SQLException to be thrown.
- Parameters:
savepoint - the Savepoint object to be removed
- Throws:
SQLException - if a database access error occurs, this
method is called on a closed connection or
the given Savepoint object is not a valid
savepoint in the current transaction
SQLFeatureNotSupportedException - if the JDBC driver does not support
this method
- Since:
- 1.4
-
createStatement
Statement createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
Creates a Statement object that will generate
ResultSet objects with the given type, concurrency,
and holdability.
This method is the same as the createStatement method
above, but it allows the default result set
type, concurrency, and holdability to be overridden.
- Parameters:
resultSetType - one of the following ResultSet
constants:
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, or
ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - one of the following ResultSet
constants:
ResultSet.CONCUR_READ_ONLY or
ResultSet.CONCUR_UPDATABLE
resultSetHoldability - one of the following ResultSet
constants:
ResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMIT
- Returns:
- a new
Statement object that will generate
ResultSet objects with the given type,
concurrency, and holdability
- Throws:
SQLException - if a database access error occurs, this
method is called on a closed connection
or the given parameters are not ResultSet
constants indicating type, concurrency, and holdability
SQLFeatureNotSupportedException - if the JDBC driver does not support
this method or this method is not supported for the specified result
set type, result set holdability and result set concurrency.
- Since:
- 1.4
- See Also:
ResultSet
-
prepareStatement
PreparedStatement prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
Creates a PreparedStatement object that will generate
ResultSet objects with the given type, concurrency,
and holdability.
This method is the same as the prepareStatement method
above, but it allows the default result set
type, concurrency, and holdability to be overridden.
- Parameters:
sql - a String object that is the SQL statement to
be sent to the database; may contain one or more '?' IN
parameters
resultSetType - one of the following ResultSet
constants:
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, or
ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - one of the following ResultSet
constants:
ResultSet.CONCUR_READ_ONLY or
ResultSet.CONCUR_UPDATABLE
resultSetHoldability - one of the following ResultSet
constants:
ResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMIT
- Returns:
- a new
PreparedStatement object, containing the
pre-compiled SQL statement, that will generate
ResultSet objects with the given type,
concurrency, and holdability
- Throws:
SQLException - if a database access error occurs, this
method is called on a closed connection
or the given parameters are not ResultSet
constants indicating type, concurrency, and holdability
SQLFeatureNotSupportedException - if the JDBC driver does not support
this method or this method is not supported for the specified result
set type, result set holdability and result set concurrency.
- Since:
- 1.4
- See Also:
ResultSet
-
prepareCall
CallableStatement prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
Creates a CallableStatement object that will generate
ResultSet objects with the given type and concurrency.
This method is the same as the prepareCall method
above, but it allows the default result set
type, result set concurrency type and holdability to be overridden.
- Parameters:
sql - a String object that is the SQL statement to
be sent to the database; may contain on or more '?' parameters
resultSetType - one of the following ResultSet
constants:
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, or
ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - one of the following ResultSet
constants:
ResultSet.CONCUR_READ_ONLY or
ResultSet.CONCUR_UPDATABLE
resultSetHoldability - one of the following ResultSet
constants:
ResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMIT
- Returns:
- a new
CallableStatement object, containing the
pre-compiled SQL statement, that will generate
ResultSet objects with the given type,
concurrency, and holdability
- Throws:
SQLException - if a database access error occurs, this
method is called on a closed connection
or the given parameters are not ResultSet
constants indicating type, concurrency, and holdability
SQLFeatureNotSupportedException - if the JDBC driver does not support
this method or this method is not supported for the specified result
set type, result set holdability and result set concurrency.
- Since:
- 1.4
- See Also:
ResultSet
-
createClob
Clob createClob()
throws SQLException
Constructs an object that implements the Clob interface. The object
returned initially contains no data. The setAsciiStream,
setCharacterStream and setString methods of
the Clob interface may be used to add data to the Clob.
- Returns:
- An object that implements the
Clob interface
- Throws:
SQLException - if an object that implements the
Clob interface can not be constructed, this method is
called on a closed connection or a database access error occurs.
SQLFeatureNotSupportedException - if the JDBC driver does not support
this data type
- Since:
- 1.6
-
createBlob
Blob createBlob()
throws SQLException
Constructs an object that implements the Blob interface. The object
returned initially contains no data. The setBinaryStream and
setBytes methods of the Blob interface may be used to add data to
the Blob.
- Returns:
- An object that implements the
Blob interface
- Throws:
SQLException - if an object that implements the
Blob interface can not be constructed, this method is
called on a closed connection or a database access error occurs.
SQLFeatureNotSupportedException - if the JDBC driver does not support
this data type
- Since:
- 1.6
-
createNClob
NClob createNClob()
throws SQLException
Constructs an object that implements the NClob interface. The object
returned initially contains no data. The setAsciiStream,
setCharacterStream and setString methods of the NClob interface may
be used to add data to the NClob.
- Returns:
- An object that implements the
NClob interface
- Throws:
SQLException - if an object that implements the
NClob interface can not be constructed, this method is
called on a closed connection or a database access error occurs.
SQLFeatureNotSupportedException - if the JDBC driver does not support
this data type
- Since:
- 1.6
-
createSQLXML
SQLXML createSQLXML()
throws SQLException
Constructs an object that implements the SQLXML interface. The object
returned initially contains no data. The createXmlStreamWriter object and
setString method of the SQLXML interface may be used to add data to the SQLXML
object.
- Returns:
- An object that implements the
SQLXML interface
- Throws:
SQLException - if an object that implements the SQLXML interface can not
be constructed, this method is
called on a closed connection or a database access error occurs.
SQLFeatureNotSupportedException - if the JDBC driver does not support
this data type
- Since:
- 1.6
-
createStruct
Struct createStruct(String typeName,
Object[] attributes)
throws SQLException
Factory method for creating Struct objects.
- Parameters:
typeName - the SQL type name of the SQL structured type that this Struct
object maps to. The typeName is the name of a user-defined type that
has been defined for this database. It is the value returned by
Struct.getSQLTypeName.
attributes - the attributes that populate the returned object
- Returns:
- a Struct object that maps to the given SQL type and is populated with the given attributes
- Throws:
SQLException - if a database error occurs, the typeName is null or this method is called on a closed connection
SQLFeatureNotSupportedException - if the JDBC driver does not support this data type
- Since:
- 1.6
-
getNetworkTimeout
int getNetworkTimeout()
throws SQLException
Retrieves the number of milliseconds the driver will
wait for a database request to complete.
If the limit is exceeded, a
SQLException is thrown.
- Returns:
- the current timeout limit in milliseconds; zero means there is
no limit
- Throws:
SQLException - if a database access error occurs or
this method is called on a closed Connection
SQLFeatureNotSupportedException - if the JDBC driver does not support
this method
- Since:
- 1.7
- See Also:
setNetworkTimeout(java.util.concurrent.Executor, int)
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|