📄 tdsconnection.java
字号:
*@exception SQLException if a database-access error occurs.
*@see #setAutoCommit
*/
public boolean getAutoCommit() throws SQLException
{
checkClosed();
return autoCommit;
}
/**
* Tests to see if a Connection is closed.
*
* @return true if the connection is closed; false if it's
* still open
* @exception SQLException if a database-access error occurs.
*/
public boolean isClosed() throws SQLException
{
return isClosed;
}
/**
* 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.
*
* @return a DatabaseMetaData object for this connection
* @exception SQLException if a database access error occurs
*/
public synchronized java.sql.DatabaseMetaData getMetaData() throws SQLException
{
checkClosed();
if( databaseMetaData == null )
// SAfe: There is always one Tds in the connection pool and we
// don't need exclusive access to it.
databaseMetaData = DatabaseMetaData.getInstance(this,
((TdsInstance)tdsPool.get(0)).tds);
return databaseMetaData;
}
/**
* Tests to see if the connection is in read-only mode.
*
* @return true if connection is read-only
* @exception SQLException if a database-access error occurs.
*/
public boolean isReadOnly() throws SQLException
{
checkClosed();
return false;
}
/**
* Return the Connection's current catalog name.
*
* @return the current catalog name or null
* @exception SQLException if a database-access error occurs.
*/
public String getCatalog() throws SQLException
{
checkClosed();
return database;
}
/**
* Get this Connection's current transaction isolation mode.
*
* @return the current TRANSACTION_* mode value
* @exception SQLException if a database-access error occurs.
*/
public int getTransactionIsolation() throws SQLException
{
checkClosed();
return transactionIsolationLevel;
}
/**
* The first warning reported by calls on this Connection is returned. <P>
*
* <B>Note:</B> Subsequent warnings will be chained to this SQLWarning.
*
* @return the first SQLWarning or null
* @exception SQLException if a database-access error occurs.
*/
public synchronized SQLWarning getWarnings() throws SQLException
{
checkClosed();
return warningChain.getWarnings();
}
/**
* JDBC 2.0 Gets the type map object associated with this connection.
* Unless the application has added an entry to the type map, the map
* returned will be empty.
*
* @return the <code>java.util.Map</code> object associated
* with this <code>Connection</code> object
* @exception SQLException Description of Exception
*/
public java.util.Map getTypeMap() throws SQLException
{
return new java.util.HashMap();
}
public synchronized void markAsClosed(java.sql.Statement stmt)
{
allStatements.removeElement(stmt);
}
/**
* 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 JDBC 2.0 Result sets created using
* the returned Statement will have forward-only type, and read-only
* concurrency, by default.
*
* @return a new Statement object
* @exception SQLException passed through from the constructor
*/
public synchronized java.sql.Statement createStatement() throws SQLException
{
checkClosed();
Statement result = new TdsStatement(this);
allStatements.addElement(result);
return result;
}
/**
* 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. <P>
*
* <B>Note:</B> 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. JDBC
* 2.0 Result sets created using the returned PreparedStatement will have
* forward-only type and read-only concurrency, by default.
*
* @param sql a SQL statement that may contain one or more '?'
* IN parameter placeholders
* @return a new PreparedStatement object containing the
* pre-compiled statement
* @exception SQLException if a database-access error occurs.
*/
public java.sql.PreparedStatement prepareStatement(String sql)
throws SQLException
{
// No need for synchronized here, prepareStatement(String, int, int) is
// synchronized
return prepareStatement(sql,
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
}
/**
* 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.
* <P>
* <B>Note:</B> This method is optimised 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 effect on users;
* however, it does affect which method throws certain SQLExceptions JDBC
* 2.0 Result sets created using the returned CallableStatement will have
* forward-only type and read-only concurrency, by default.
*
* @param sql a SQL statement that may contain one or more '?'
* parameter placeholders. Typically this statement is a JDBC function
* call escape string.
* @return a new CallableStatement object containing the
* pre-compiled SQL statement
* @exception SQLException if a database access error occurs
*/
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
{
// No need for synchronized here, prepareCall(String, int, int) is
// synchronized
return prepareCall(sql,
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
}
/**
* 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.
*
* @param sql a SQL statement that may contain one or more '?'
* parameter placeholders
* @return the native form of this statement
* @exception SQLException if a database access error occurs
*/
public String nativeSQL(String sql) throws SQLException
{
return Tds.toNativeSql(sql, serverType);
}
/**
* 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.
*
* @exception SQLException if a database-access error occurs.
* @see #setAutoCommit
*/
public synchronized void commit() throws SQLException
{
commitOrRollback(true);
}
/**
* 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.
*
* @exception SQLException if a database-access error occurs.
* @see #setAutoCommit
*/
public synchronized void rollback() throws SQLException
{
commitOrRollback(false);
}
/**
* 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. <P>
*
* <B>Note:</B> A Connection is automatically closed when it is garbage
* collected. Certain fatal errors also result in a closed Connection.
*
* @exception SQLException if a database-access error occurs.
*/
public synchronized void close() throws SQLException
{
int i;
SQLException exception = null;
// SAfe First close all Statements, to ensure nothing is left behind
// This is needed to ensure rollback below doesn't crash.
// SAfe Need to do it backwards because when closing, Statements remove
// themselves from the list.
for( i=allStatements.size()-1; i>=0; i-- )
try
{
((Statement)allStatements.elementAt(i)).close();
}
catch( SQLException ex )
{
// SAfe Add the old exceptions to the chain
ex.setNextException(exception);
exception = ex;
}
allStatements.clear();
// MJH Need to rollback if in manual commit mode
for( i=0; i<tdsPool.size(); i++ )
{
try
{
// SAfe Maybe we should commit regardless of the fact that we're in manual commit mode or not. There
// might be uncommited statements, anyway (e.g. we were in manual commit mode, executed some
// queries, went into auto commit mode but did not commit them).
Tds tds = ((TdsInstance)tdsPool.elementAt(i)).tds;
synchronized( tds )
{
if( !autoCommit )
tds.rollback(); // MJH
tds.close();
}
}
catch( SQLException ex )
{
// SAfe Add the exception to the chain
exception.setNextException(ex);
}
}
tdsPool.clear();
clearWarnings();
isClosed = true;
if( exception != null )
throw exception;
}
/**
* After this call, getWarnings returns null until a new warning is
* reported for this connection.
*
* @exception SQLException if a database access error occurs
*/
public synchronized void clearWarnings() throws SQLException
{
checkClosed();
warningChain.clearWarnings();
}
//--------------------------JDBC 2.0-----------------------------
/**
* JDBC 2.0 Creates a <code>Statement</code> object that will generate
* <code>ResultSet</code> objects with the given type and concurrency. This
* method is the same as the <code>createStatement</code> method above, but
* it allows the default result set type and result set concurrency type to
* be overridden.
*
* @param type a result set type; see ResultSet.TYPE_XXX
* @param concurrency a concurrency type; see ResultSet.CONCUR_XXX
* @return a new Statement object
* @exception SQLException if a database access error occurs
*/
public synchronized java.sql.Statement createStatement(int type, int concurrency)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -