|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.infosoftglobal.fusioncharts.DBConnection
public class DBConnection
Contains methods to get a connection to the database.
The database could be MS Access or MySQL
This class contains database specific code to connect to the database Access or MySQL
Only one instance of this class should ideally be used throughtout 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.
In the current application,InitServlet
instantiates this class and sets all the
variables like dbName,accessDBPath & mySQLDSN and puts that instance in the application context
so that it is available to all the jsps.
Field Summary | |
---|---|
private java.lang.String |
accessDBPath
Deprecated. Path to the access DB |
private java.lang.String |
dbName
Deprecated. Name of the database to be used |
private java.lang.String |
mySQLDSN
Deprecated. DSN for the MySql DB |
Constructor Summary | |
---|---|
DBConnection()
Deprecated. |
Method Summary | |
---|---|
java.lang.String |
getAccessDBPath()
Deprecated. Gets the path to the Access DB |
java.sql.Connection |
getConnection()
Deprecated. 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. |
java.sql.Connection |
getConnection(javax.servlet.ServletContext context)
Deprecated. Gets a connection to the specific database as given in configuration file. First it checks connection to which database is required then it calls the appropriate getConnection method 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. |
private java.sql.Connection |
getConnection(java.lang.String pathToDB)
Deprecated. Opens the connection to the Access Database The complete path to the mdb comes from configuration file web.xml. Here we are just printing the stack trace in case of any exception. In real world applications,some kind of exception-handling needs to be done. Further,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. |
private java.sql.Connection |
getConnectionByDSN(java.lang.String dataSourceName)
Deprecated. 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. |
java.lang.String |
getDbName()
Deprecated. Gets the Database Name for the current instance |
java.lang.String |
getMySQLDSN()
Deprecated. Gets the DSN for MySQLDB |
void |
setAccessDBPath(java.lang.String accessDBPath)
Deprecated. Sets the path to the AccessDB |
void |
setDbName(java.lang.String dbName)
Deprecated. Sets the Database Name for the current instance |
void |
setMySQLDSN(java.lang.String mySQLDSN)
Deprecated. Sets the DSN for MySQLDB |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String dbName
private java.lang.String accessDBPath
private java.lang.String mySQLDSN
Constructor Detail |
---|
public DBConnection()
Method Detail |
---|
public java.sql.Connection getConnection()
public java.sql.Connection getConnection(javax.servlet.ServletContext context)
context
- ServletContext of the server requesting connection
private java.sql.Connection getConnectionByDSN(java.lang.String dataSourceName)
private java.sql.Connection getConnection(java.lang.String pathToDB)
pathToDB
- - the path to the mdb file
public java.lang.String getAccessDBPath()
public void setAccessDBPath(java.lang.String accessDBPath)
accessDBPath
- - path to the Access DBpublic java.lang.String getDbName()
public void setDbName(java.lang.String dbName)
dbName
- public java.lang.String getMySQLDSN()
public void setMySQLDSN(java.lang.String mySQLDSN)
mySQLDSN
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |