| java.lang.Object com.salmonllc.sql.DBConnection
DBConnection | public class DBConnection (Code) | | This class abstracts and simplifies the process of getting database connections from connection pools and connection managers, provides some transaction support as well as a wrapper for the java.sql.Connection class.
The constructor for this class is private. The only way to get an instance of the class is to use one of the static "getConnection" methods shown below.
An important note:
In order for connection pooling to operate properly, the connection must be released when it is no longer needed.
Example usage:
DBConnection conn = null;
try {
conn =DBConnection.getConnection("Application1");
...Sql Statements using the connection
}
catch (SQLException e) {
..handle error
}
finally {
if (conn != null)
conn.freeConnection();
}
See Also: java.sql.Connection See Also: java.sql.Statement See Also: java.sql.PreparedStatement |
Constructor Summary | |
| DBConnection(Connection conn, String type, boolean direct, boolean dataSource) This method was created in VisualAge. | | DBConnection(Connection conn, String type, boolean direct, boolean dataSource, String dbName) Create a DBConnection
Parameters: conn - java.sql.Connection Parameters: type - The database type (mySQL, DB2, Oracle, etc..) Parameters: direct - If true, by-pass the local connection pool Parameters: dataSource - If true, use the app-server dataSource specified in the properties file Parameters: dbName - Database name. |
Method Summary | |
public void | beginTransaction() Marks the logical beginning of a transaction. | public void | beginTransaction(String fromWhere) Marks the logical beginning of a transaction. | public void | commit() This method commits a transaction started by a call to the beginTransaction method. | public void | commit(String fromWhere) This method commits a transaction started by a call to the beginTransaction method. | public java.sql.Statement | createStatement() SQL statements without parameters are normally executed using Statement objects. | public synchronized void | freeConnection() Returns the connection back to the connection pool for use by other processes. | String | getApplication() | public static synchronized DBConnection | getConnection(int maxConnections, long waitTimeout, long idleTimeout, String DBMS, String jdbcDriver, String databaseURL, String userID, String password, String dbName, String connectionParms) This method will create a new database connection using the information passed to it. | public static synchronized DBConnection | getConnection(int maxConnections, long waitTimeout, long idleTimeout, String DBMS, String jdbcDriver, String databaseURL, String userID, String password, String dbName) This method will create a new database connection using the information passed to it. | public static DBConnection | getConnection(String application) This method returns the default database connection for a particular application. | public static DBConnection | getConnection(String application, String name) This method will search a properties file for a particular application for information on connecting to a database
with the specified name and returns a DBConnection attached to it. | public static Enumeration | getConnectionLists() This method returns an enumeration of all the connection pools maintained by the system. | String | getConnectionParm(String key) | Hashtable | getConnectionParms() | public String | getDBMS() This method returns the DBMS that the object is connected to. | public String | getDBName() | public DataDictionary | getDataDictionary() Returns a data dictionary object containing information on the tables in this database. | public static DBConnection | getDirectConnection(String url, String driverName, String user, String passwd) Use this method to get a connection to the database without using connection pooling. | public static DBConnection | getDirectConnection(String dbms, String url, String driverName, String user, String passwd) Use this method to get a connection to the database without using connection pooling. | public static DBConnection | getDirectConnection(String dbms, String url, String driverName, String dbName, String user, String passwd) Use this method to get a connection to the database without using connection pooling. | public boolean | getInUse() This method will return whether the Connection is currently being used. | public Connection | getJDBCConnection() This method will return the actual JDBC connection that this class is a wrapper for. | public long | getLastDuration() | public String | getLastSQL() | public long | getLastUsed() This method will return that time in millseconds that the connection was last used. | DBConnection | getNext() | DBConnection | getPrior() | String | getProfileName() | public boolean | isTransactionStarted() true if a transaction has been started on this connection but not yet committed or rolled back. | static Hashtable | parseConnectionParms(String parms) | public java.sql.CallableStatement | prepareCall(String sql) A SQL stored procedure call statement is handled by creating a CallableStatement for it. | public java.sql.PreparedStatement | prepareStatement(String sql) A SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. | synchronized void | registerRetrieve(DataStore d) | public void | rollback() This method rolls back a transaction started by a call to the beginTransaction method. | public void | rollback(String fromWhere) This method rolls back a transaction started by a call to the beginTransaction method. | void | setConnectionParms(Hashtable hashtable) | void | setCreated(long lCreated) This method will set the creation time of the connection. | void | setDBName(String dbName) | void | setDataSource(DataSource ds) This method will store the datasource the connection was created with. | void | setDatabaseDriver(String driverName) This method will store the database driver the connection was created with. | void | setDatabaseUrl(String url) This method will store the database Url the connection was created with. | void | setInUse(boolean inUse) This method will set whether the Connection is currently being used. | void | setJDBCConnection(Connection conn) | void | setLastDuration(long lastDuration) This method will set whether the last duration for the connection. | void | setLastSQL(String sql) | void | setLastUsed(long lastUsed) This method will set whether the Connection is currently being used. | void | setList(DBConnectionList list) | void | setNext(DBConnection conn) | void | setPassword(String pass) This method will store the password the connection was created with. | void | setPrior(DBConnection conn) | void | setUserName(String user) This method will store the username the connection was created with. | void | setVerifyConnection(boolean bVerify) This method will indicate whether a connection should be verified. | void | setVerifyConnectionMaxAge(int iMaxAge) This method will set the connections verification max age in seconds. | void | setVerifyConnectionStatement(String sVerifyStatement) This method will set the connection verify statement. | synchronized void | unregisterRetrieve(DataStore d) |
ANSISQL92_CONNECTION | final public static String ANSISQL92_CONNECTION(Code) | | |
DB2400_CONNECTION | final public static String DB2400_CONNECTION(Code) | | |
DB2MVS_CONNECTION | final public static String DB2MVS_CONNECTION(Code) | | |
DB2VSE_CONNECTION | final public static String DB2VSE_CONNECTION(Code) | | |
DB2_CONNECTION | final public static String DB2_CONNECTION(Code) | | |
FIREBIRDSQL_CONNECTION | final public static String FIREBIRDSQL_CONNECTION(Code) | | |
INGRES_CONNECTION | final public static String INGRES_CONNECTION(Code) | | |
MSSQLSEVER_CONNECTION | final public static String MSSQLSEVER_CONNECTION(Code) | | |
MYSQL_CONNECTION | final public static String MYSQL_CONNECTION(Code) | | |
ORACLE_CONNECTION | final public static String ORACLE_CONNECTION(Code) | | |
POSTGRES_CONNECTION | final public static String POSTGRES_CONNECTION(Code) | | |
SQLANYWHERE_CONNECTION | final public static String SQLANYWHERE_CONNECTION(Code) | | |
SYBASE_CONNECTION | final public static String SYBASE_CONNECTION(Code) | | |
DBConnection | DBConnection(Connection conn, String type, boolean direct, boolean dataSource)(Code) | | This method was created in VisualAge.
Parameters: conn - java.sql.Connection Parameters: type - java.lang.String |
DBConnection | DBConnection(Connection conn, String type, boolean direct, boolean dataSource, String dbName)(Code) | | Create a DBConnection
Parameters: conn - java.sql.Connection Parameters: type - The database type (mySQL, DB2, Oracle, etc..) Parameters: direct - If true, by-pass the local connection pool Parameters: dataSource - If true, use the app-server dataSource specified in the properties file Parameters: dbName - Database name. Used by various implementations. Usually null. |
freeConnection | public synchronized void freeConnection()(Code) | | Returns the connection back to the connection pool for use by other processes.
|
getApplication | String getApplication()(Code) | | Returns the application. |
getConnection | public static synchronized DBConnection getConnection(int maxConnections, long waitTimeout, long idleTimeout, String DBMS, String jdbcDriver, String databaseURL, String userID, String password, String dbName, String connectionParms) throws java.sql.SQLException(Code) | | This method will create a new database connection using the information passed to it.
The connection created from the passed. Parameters: maxConnections - The maximum number of database connections of this type that can be used concurrently. Parameters: waitTimeout - The time in milliseconds to wait for a connection before throwing an exception. Parameters: idleTimeout - The time in milliseconds for a connection to remain idle before it is disconnected from the database. Parameters: DBMS - The name of the DBMS you are using. Parameters: jdbcDriver - The name of the jdbc driver for this connection. Parameters: databaseURL - The url for the specific database that you want to connect to. Parameters: userID - A valid user in the specified database. Parameters: password - The password for the specified user. Parameters: dbName - The database name used for this connection. Parameters: connectionParms - A string of semicolon seperated values that tell the connection and datastores that use it how to behave exception: java.sql.SQLException - |
getConnection | public static synchronized DBConnection getConnection(int maxConnections, long waitTimeout, long idleTimeout, String DBMS, String jdbcDriver, String databaseURL, String userID, String password, String dbName) throws java.sql.SQLException(Code) | | This method will create a new database connection using the information passed to it.
The connection created from the passed. Parameters: maxConnections - The maximum number of database connections of this type that can be used concurrently. Parameters: waitTimeout - The time in milliseconds to wait for a connection before throwing an exception. Parameters: idleTimeout - The time in milliseconds for a connection to remain idle before it is disconnected from the database. Parameters: DBMS - The name of the DBMS you are using. Parameters: jdbcDriver - The name of the jdbc driver for this connection. Parameters: databaseURL - The url for the specific database that you want to connect to. Parameters: userID - A valid user in the specified database. Parameters: password - The password for the specified user. Parameters: dbName - The database name used for this connection. exception: java.sql.SQLException - |
getConnection | public static DBConnection getConnection(String application) throws java.sql.SQLException(Code) | | This method returns the default database connection for a particular application.
the default connection for a particular application as indicated in the properties file. Parameters: application - The name to search under for connection information. exception: java.sql.SQLException - |
getConnection | public static DBConnection getConnection(String application, String name) throws java.sql.SQLException(Code) | | This method will search a properties file for a particular application for information on connecting to a database
with the specified name and returns a DBConnection attached to it.
The connection created from the information found in the property file. Parameters: name - The name to search under for connection information. exception: java.sql.SQLException - |
getConnectionLists | public static Enumeration getConnectionLists()(Code) | | This method returns an enumeration of all the connection pools maintained by the system.
|
getConnectionParm | String getConnectionParm(String key)(Code) | | This method returns a connection parameter
Parameters: key - |
getConnectionParms | Hashtable getConnectionParms()(Code) | | Returns a Hashtable of connection parms used for this connection
|
getDBMS | public String getDBMS()(Code) | | This method returns the DBMS that the object is connected to.
SYBASE_CONNECTION, DB2_CONNECTION or SQLANYWHERE_CONNECTION. |
getDBName | public String getDBName()(Code) | | This method returns the DBName used by the connection (used for DB2)
|
getDataDictionary | public DataDictionary getDataDictionary()(Code) | | Returns a data dictionary object containing information on the tables in this database. The DataDictionary object should only be used for the time that the connection object is help (between the DBConnection.getConnection() and DBConnection.freeConnection() methods)
|
getDirectConnection | public static DBConnection getDirectConnection(String url, String driverName, String user, String passwd) throws java.sql.SQLException(Code) | | Use this method to get a connection to the database without using connection pooling.
Parameters: url - The url for the specific database that you want to connect to. Parameters: driverName - The name of the jdbc driver for this connection. Parameters: user - A valid user in the specified database. Parameters: passwd - The password for the specified user. |
getDirectConnection | public static DBConnection getDirectConnection(String dbms, String url, String driverName, String user, String passwd) throws java.sql.SQLException(Code) | | Use this method to get a connection to the database without using connection pooling.
Parameters: url - The url for the specific database that you want to connect to. Parameters: driverName - The name of the jdbc driver for this connection. Parameters: user - A valid user in the specified database. Parameters: passwd - The password for the specified user. |
getDirectConnection | public static DBConnection getDirectConnection(String dbms, String url, String driverName, String dbName, String user, String passwd) throws java.sql.SQLException(Code) | | Use this method to get a connection to the database without using connection pooling.
Parameters: dbms - The Database Management System you are using. Parameters: url - The url for the specific database that you want to connect to. Parameters: driverName - The name of the jdbc driver for this connection. Parameters: user - A valid user in the specified database. Parameters: passwd - The password for the specified user. |
getInUse | public boolean getInUse()(Code) | | This method will return whether the Connection is currently being used.
|
getJDBCConnection | public Connection getJDBCConnection()(Code) | | This method will return the actual JDBC connection that this class is a wrapper for.
|
getLastDuration | public long getLastDuration()(Code) | | This method will return that time in millseconds that it took between the last time the connection was requested and released
|
getLastSQL | public String getLastSQL()(Code) | | This method will return the last SQL statement that was executed on the connection
|
getLastUsed | public long getLastUsed()(Code) | | This method will return that time in millseconds that the connection was last used.
|
getProfileName | String getProfileName()(Code) | | Returns the profileName. |
isTransactionStarted | public boolean isTransactionStarted()(Code) | | true if a transaction has been started on this connection but not yet committed or rolled back. If the transaction has not been, it will be rolled back when the connection has been returned to the pool. |
prepareCall | public java.sql.CallableStatement prepareCall(String sql) throws java.sql.SQLException(Code) | | 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.
a new CallableStatement object containing the pre-compiled SQL statement Parameters: sql - a SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is a JDBC function call escape string. exception: java.sql.SQLException - |
prepareStatement | public java.sql.PreparedStatement prepareStatement(String sql) throws java.sql.SQLException(Code) | | 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.
a new PreparedStatement object containing the pre-compiled statement. Parameters: sql - a SQL statement that may contain one or more '?' IN parameter placeholders exception: java.sql.SQLException - |
setCreated | void setCreated(long lCreated)(Code) | | This method will set the creation time of the connection.
|
setDataSource | void setDataSource(DataSource ds)(Code) | | This method will store the datasource the connection was created with.
|
setDatabaseDriver | void setDatabaseDriver(String driverName)(Code) | | This method will store the database driver the connection was created with.
|
setDatabaseUrl | void setDatabaseUrl(String url)(Code) | | This method will store the database Url the connection was created with.
|
setInUse | void setInUse(boolean inUse)(Code) | | This method will set whether the Connection is currently being used.
|
setLastDuration | void setLastDuration(long lastDuration)(Code) | | This method will set whether the last duration for the connection.
|
setLastSQL | void setLastSQL(String sql)(Code) | | This method will set the last SQL statement that was executed on the connection
|
setLastUsed | void setLastUsed(long lastUsed)(Code) | | This method will set whether the Connection is currently being used.
|
setPassword | void setPassword(String pass)(Code) | | This method will store the password the connection was created with.
|
setUserName | void setUserName(String user)(Code) | | This method will store the username the connection was created with.
|
setVerifyConnection | void setVerifyConnection(boolean bVerify)(Code) | | This method will indicate whether a connection should be verified.
|
setVerifyConnectionMaxAge | void setVerifyConnectionMaxAge(int iMaxAge)(Code) | | This method will set the connections verification max age in seconds.
If the connection is older than the max age the connection will be reestablished.
|
setVerifyConnectionStatement | void setVerifyConnectionStatement(String sVerifyStatement)(Code) | | This method will set the connection verify statement.
|
|
|