|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.fusioncharts.database.DBConnection
public class DBConnection
Contains methods to get a connection to the database.
The database used here is MySQL
This class contains code to connect to the database
The DSN looked up for connection is "jdbc/FactoryDB". Please configure the same DSN in your server.
Only one instance of this class should ideally be used throughout your application.
For demo purpose, we have kept the default constructor available to all classes.
Ideally you would override the default constructor and write a getInstance method which will
return a single DBConnection instance always,thus making it a singleton class.
Constructor Summary | |
---|---|
DBConnection()
|
Method Summary | |
---|---|
java.sql.Connection |
getConnection()
Returns a connection to a database as configured earlier. This method can be used by all the jsps to get a connection. The jsps do not have to worry about which db to connect to etc. This has been configured in this class by the InitServlet. |
private java.sql.Connection |
getConnectionByDSN(java.lang.String dataSourceName)
Opens the connection to the MySQL Database Using the DataSource Name specified in the config file of the server in which it is deployed. In real world applications,some sort of connection pooling mechanism would be used for getting the connection and proper care would be taken to close it when the work is done. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DBConnection()
Method Detail |
---|
public java.sql.Connection getConnection()
private java.sql.Connection getConnectionByDSN(java.lang.String dataSourceName)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |