Java Doc for DBConnection.java in  » J2EE » Sofia » com » salmonllc » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.sql 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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


Field Summary
final public static  StringANSISQL92_CONNECTION
    
final public static  StringDB2400_CONNECTION
    
final public static  StringDB2MVS_CONNECTION
    
final public static  StringDB2VSE_CONNECTION
    
final public static  StringDB2_CONNECTION
    
final public static  StringFIREBIRDSQL_CONNECTION
    
final public static  StringINGRES_CONNECTION
    
final public static  StringMSSQLSEVER_CONNECTION
    
final public static  StringMYSQL_CONNECTION
    
final public static  StringORACLE_CONNECTION
    
final public static  StringPOSTGRES_CONNECTION
    
final public static  StringSQLANYWHERE_CONNECTION
    
final public static  StringSYBASE_CONNECTION
    

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  voidbeginTransaction()
     Marks the logical beginning of a transaction.
public  voidbeginTransaction(String fromWhere)
     Marks the logical beginning of a transaction.
public  voidcommit()
     This method commits a transaction started by a call to the beginTransaction method.
public  voidcommit(String fromWhere)
     This method commits a transaction started by a call to the beginTransaction method.
public  java.sql.StatementcreateStatement()
     SQL statements without parameters are normally executed using Statement objects.
public synchronized  voidfreeConnection()
     Returns the connection back to the connection pool for use by other processes.
 StringgetApplication()
    
public static synchronized  DBConnectiongetConnection(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  DBConnectiongetConnection(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  DBConnectiongetConnection(String application)
     This method returns the default database connection for a particular application.
public static  DBConnectiongetConnection(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  EnumerationgetConnectionLists()
     This method returns an enumeration of all the connection pools maintained by the system.
 StringgetConnectionParm(String key)
    
 HashtablegetConnectionParms()
    
public  StringgetDBMS()
     This method returns the DBMS that the object is connected to.
public  StringgetDBName()
    
public  DataDictionarygetDataDictionary()
     Returns a data dictionary object containing information on the tables in this database.
public static  DBConnectiongetDirectConnection(String url, String driverName, String user, String passwd)
     Use this method to get a connection to the database without using connection pooling.
public static  DBConnectiongetDirectConnection(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  DBConnectiongetDirectConnection(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  booleangetInUse()
     This method will return whether the Connection is currently being used.
public  ConnectiongetJDBCConnection()
     This method will return the actual JDBC connection that this class is a wrapper for.
public  longgetLastDuration()
    
public  StringgetLastSQL()
    
public  longgetLastUsed()
     This method will return that time in millseconds that the connection was last used.
 DBConnectiongetNext()
    
 DBConnectiongetPrior()
    
 StringgetProfileName()
    
public  booleanisTransactionStarted()
     true if a transaction has been started on this connection but not yet committed or rolled back.
static  HashtableparseConnectionParms(String parms)
    
public  java.sql.CallableStatementprepareCall(String sql)
     A SQL stored procedure call statement is handled by creating a CallableStatement for it.
public  java.sql.PreparedStatementprepareStatement(String sql)
     A SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object.
synchronized  voidregisterRetrieve(DataStore d)
    
public  voidrollback()
     This method rolls back a transaction started by a call to the beginTransaction method.
public  voidrollback(String fromWhere)
     This method rolls back a transaction started by a call to the beginTransaction method.
 voidsetConnectionParms(Hashtable hashtable)
    
 voidsetCreated(long lCreated)
     This method will set the creation time of the connection.
 voidsetDBName(String dbName)
    
 voidsetDataSource(DataSource ds)
     This method will store the datasource the connection was created with.
 voidsetDatabaseDriver(String driverName)
     This method will store the database driver the connection was created with.
 voidsetDatabaseUrl(String url)
     This method will store the database Url the connection was created with.
 voidsetInUse(boolean inUse)
     This method will set whether the Connection is currently being used.
 voidsetJDBCConnection(Connection conn)
    
 voidsetLastDuration(long lastDuration)
     This method will set whether the last duration for the connection.
 voidsetLastSQL(String sql)
    
 voidsetLastUsed(long lastUsed)
     This method will set whether the Connection is currently being used.
 voidsetList(DBConnectionList list)
    
 voidsetNext(DBConnection conn)
    
 voidsetPassword(String pass)
     This method will store the password the connection was created with.
 voidsetPrior(DBConnection conn)
    
 voidsetUserName(String user)
     This method will store the username the connection was created with.
 voidsetVerifyConnection(boolean bVerify)
     This method will indicate whether a connection should be verified.
 voidsetVerifyConnectionMaxAge(int iMaxAge)
     This method will set the connections verification max age in seconds.
 voidsetVerifyConnectionStatement(String sVerifyStatement)
     This method will set the connection verify statement.
synchronized  voidunregisterRetrieve(DataStore d)
    

Field Detail
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)




Constructor Detail
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.




Method Detail
beginTransaction
public void beginTransaction() throws java.sql.SQLException(Code)
Marks the logical beginning of a transaction. The transaction must be completed later in the code via a call to either commit or rollback methods.
See Also:   DBConnection.commit
See Also:   DBConnection.rollback



beginTransaction
public void beginTransaction(String fromWhere) throws java.sql.SQLException(Code)
Marks the logical beginning of a transaction. The transaction must be completed later in the code via a call to either commit or rollback methods.
exception:
  java.sql.SQLException - The SQL Exception.
See Also:   DBConnection.commit
See Also:   DBConnection.rollback



commit
public void commit()(Code)
This method commits a transaction started by a call to the beginTransaction method.
See Also:   DBConnection.beginTransaction
See Also:   DBConnection.rollback



commit
public void commit(String fromWhere)(Code)
This method commits a transaction started by a call to the beginTransaction method.
See Also:   DBConnection.beginTransaction
See Also:   DBConnection.rollback



createStatement
public java.sql.Statement createStatement() throws java.sql.SQLException(Code)
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 new Statement object
exception:
  java.sql.SQLException -



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.



getNext
DBConnection getNext()(Code)



getPrior
DBConnection getPrior()(Code)



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.



parseConnectionParms
static Hashtable parseConnectionParms(String parms)(Code)



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 -



registerRetrieve
synchronized void registerRetrieve(DataStore d)(Code)



rollback
public void rollback()(Code)
This method rolls back a transaction started by a call to the beginTransaction method.
See Also:   DBConnection.beginTransaction
See Also:   DBConnection.commit



rollback
public void rollback(String fromWhere)(Code)
This method rolls back a transaction started by a call to the beginTransaction method.
See Also:   DBConnection.beginTransaction
See Also:   DBConnection.commit



setConnectionParms
void setConnectionParms(Hashtable hashtable)(Code)



setCreated
void setCreated(long lCreated)(Code)
This method will set the creation time of the connection.



setDBName
void setDBName(String dbName)(Code)



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.



setJDBCConnection
void setJDBCConnection(Connection conn)(Code)



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.



setList
void setList(DBConnectionList list)(Code)



setNext
void setNext(DBConnection conn)(Code)



setPassword
void setPassword(String pass)(Code)
This method will store the password the connection was created with.



setPrior
void setPrior(DBConnection conn)(Code)



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.



unregisterRetrieve
synchronized void unregisterRetrieve(DataStore d)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.