java.lang.Object
|
+--stec.sql.Connection
public class Connection extends Object implements java.sql.Connection
A session to a specific database used to execute SQL statements.
Fields
Methods
Method
|
Description
|
clearWarnings
|
Clears all warnings.
|
close
|
Returns this connection to the connection pool.
|
commit
|
Makes all changes made since the last commit/rollback permanent and
releases any locks held.
|
createStatement
|
Returns a new SQL Statement object.
|
getAutoCommit
|
Gets the current state of auto-commit.
|
getCatalog
|
Returns current catalog name.
|
getMetaData
|
Returns the database meta data.
|
getTransactionIsolation
|
Returns the current transaction isolation level.
|
getTypeMap
|
Returns the current Map object used to map custom SQL types.
|
getWarnings
|
Returns the first warning.
|
isClosed
|
Returns whether this connection was returned to the connection pool.
|
isReadOnly
|
Returns whether in read-only mode.
|
nativeSQL
|
Returns the native form of the given SQL statement.
|
prepareCall
|
Creates a CallableStatement object from the given SQL statement for calling
database stored procedures.
|
prepareStatement
|
Creates a PreparedStatement object from the given parameterized SQL statement.
|
rollback
|
Rolls back all changes made since the last commit/rollback and releases any
locks held.
|
setAutoCommit
|
Sets the auto-commit mode.
|
setCatalog
|
Sets the catalog name.
|
setReadOnly
|
Sets the read-only mode.
|
setTransactionIsolation
|
Sets the transaction isolation level.
|
setTypeMap
|
Sets the Map object used to map custom SQL types.
|
Notes
Unless auto-commit mode has been disabled, a connection automatically commits
changes after each statement. If auto-commit mode has been disabled, a commit
must be done or changes to the database will not be made.
TRANSACTION_NONE
Transactions are not supported.
Syntax
public static final int TRANSACTION_NONE
Example
int level = Connection.TRANSACTION_NONE;
TRANSACTION_READ_COMMITTED
Prevent dirty reads. Allow non-repeatable reads and phantom reads.
Syntax
public static final int TRANSACTION_READ_COMMITTED
Example
int level = Connection.TRANSACTION_READ_COMMITTED;
TRANSACTION_READ_UNCOMMITTED
Allow dirty reads, non-repeatable reads and phantom reads.
Syntax
public static final int TRANSACTION_READ_UNCOMMITTED
Example
int level = Connection.TRANSACTION_READ_UNCOMMITTED;
TRANSACTION_REPEATABLE_READ
Prevent dirty reads and non-repeatable reads. Allow phantom reads.
Syntax
public static final int TRANSACTION_REPEATABLE_READ
Example
int level = Connection.TRANSACTION_REPEATABLE_READ;
TRANSACTION_SERIALIZABLE
Prevent dirty reads, non-repeatable reads and phantom reads.
Syntax
public static final int TRANSACTION_SERIALIZABLE
Example
int level = Connection.TRANSACTION_SERIALIZABLE;
clearWarnings
Clears all warnings.
Syntax
public void clearWarnings() throws SQLException
Parameters
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.clearWarnings();
close
Returns this connection to the connection pool.
Syntax
public void close() throws SQLException
Parameters
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.close();
commit
Makes all changes made since the last commit/rollback permanent and
releases any locks held.
Syntax
public void commit() throws SQLException
Parameters
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.commit();
createStatement
Returns a new SQL Statement object.
Syntax
public Statement createStatement() throws SQLException
public Statement createStatement(int type, int concurrency)
throws SQLException
Parameters
type
|
the ResultSet type, ResultSet.TYPE_type.
|
concurrency
|
the ResultSet concurrency type, ResultSet.CONCUR_concurrency.
|
Returns
Statement
|
a new SQL Statement object.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
Statement stmt = con.createStatement();
getAutoCommit
Gets the current state of auto-commit.
Syntax
public boolean getAutoCommit() throws SQLException
Parameters
Returns
boolean
|
true if in auto-commit mode, false if not.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
if(!con.getAutoCommit()) con.commit()
getCatalog
Returns current catalog name.
Syntax
public String getCatalog() throws SQLException
Parameters
Returns
String
|
the current catalog name, null if none.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
catalog = con.getCatalog()
getMetaData
Returns the database meta data.
Syntax
public DatabaseMetaData getMetaData() throws SQLException
Parameters
Returns
DatabaseMetaData
|
a DatabaseMetaData object.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
DatabaseMetaData metadata = con.getMetaData()
getTransactionIsolation
Returns the current transaction isolation level.
Syntax
public int getTransactionIsolation() throws SQLException
Parameters
Returns
int
|
the current transaction isolation level.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
int level = con.getTransactionIsolation()
getTypeMap
Returns the current Map object used to map custom SQL types.
Syntax
public Map getTypeMap() throws SQLException
Parameters
Returns
Map
|
the current Map object used to map custom SQL types.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
Map map = con.getTypeMap()
getWarnings
Returns the first SQL warning.
Syntax
public SQLWarning getWarnings() throws SQLException
Parameters
Returns
SQLWarning
|
the first SQLWarning, null if none.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
SQLWarning warning = con.getWarnings()
isClosed
Returns whether this connection was returned to the connection pool.
Syntax
public boolean isClosed() throws SQLException
Parameters
Returns
boolean
|
true if the connection was returned to the connection pool, false if not.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
if(!con.isClosed()) con.close()
isReadOnly
Returns whether in read-only mode.
Syntax
public boolean isReadOnly() throws SQLException
Parameters
Returns
boolean
|
true if in read-only mode, false if not.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
if(!con.isReadOnly()) update(con, record);
nativeSQL
Returns the native form of the given SQL statement.
Syntax
public String nativeSQL(String sql) throws SQLException
Parameters
sql
|
the SQL statement to convert.
|
Returns
String
|
the native form the the specified SQL statement.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
String native = con.nativeSQL(sql);
prepareCall
Creates a CallableStatement object from the given SQL statement for calling
database stored procedures.
Syntax
public CallableStatement prepareCall(String sql)
throws SQLException
public CallableStatement prepareCall(String sql,
int type,
int concurrency)
throws SQLException
Parameters
sql
|
the SQL statement.
|
type
|
the ResultSet type, ResultSet.TYPE_type.
|
concurrency
|
the ResultSet concurrency type, ResultSet.CONCUR_concurrency.
|
Returns
CallableStatement
|
a new CallableStatement object.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
CallableStatement stmt = con.prepareCall(sql);
prepareStatement
Creates a PreparedStatement object from the given parameterized SQL statement.
Syntax
public PreparedStatement prepareStatement(String sql)
throws SQLException
public PreparedStatement prepareStatement(String sql,
int type,
int concurrency)
throws SQLException
Parameters
sql
|
the SQL statement.
|
type
|
the ResultSet type, ResultSet.TYPE_type.
|
concurrency
|
the ResultSet concurrency type, ResultSet.CONCUR_concurrency.
|
Returns
PreparedStatement
|
a new PreparedStatement object.
|
Throws
SQLException
|
if a database access error occurs.
|
Example
PreparedStatement stmt = con.prepareStatement(sql);
rollback
Rolls back all changes made since the last commit/rollback and releases any
locks held.
Syntax
public void rollback() throws SQLException
Parameters
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.rollback();
setAutoCommit
Sets the auto-commit mode.
Syntax
public void setAutoCommit(boolean autoCommit) throws SQLException
Parameters
autoCommit
|
true to enable auto-commit mode, false to disable auto-commit mode.
|
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.setAutoCommit(true);
setCatalog
Sets the catalog name.
Syntax
public void setCatalog(String catalog) throws SQLException
Parameters
catalog
|
the catalog's name.
|
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.setCatalog(catalog);
setReadOnly
Sets the read-only mode.
Syntax
public void setReadOnly(boolean readOnly) throws SQLException
Parameters
readOnly
|
true to enable read-only mode, false to disable read-only mode.
|
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.setReadOnly(true);
setTransactionIsolation
Sets the transaction isolation level.
Syntax
public void setTransactionIsolation(int level) throws SQLException
Parameters
level
|
the transaction isolation level.
|
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.setTransactionIsolation(level);
setTransactionIsolation
Sets the transaction isolation level.
Syntax
public void setTypeMap(Map typemap) throws SQLException
Parameters
typemap
|
the Map object used to map custom SQL types.
|
Returns
Throws
SQLException
|
if a database access error occurs.
|
Example
con.setTypeMap(typemap);
|