Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.infosoftglobal.fusioncharts
Class DBConnection

    java.lang.Object
      com.infosoftglobal.fusioncharts.DBConnection

public class DBConnection
extends java.lang.Object

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.

Author:
  InfoSoft Global (P) Ltd.

Field Summary
`private java.lang.String` | `accessDBPath` Path to the access DB
`private java.lang.String` | `dbName` Name of the database to be used
`private java.lang.String` | `mySQLDSN` DSN for the MySql DB

Constructor Summary
`DBConnection()`

Method Summary
`java.lang.String` | `getAccessDBPath()` Gets the path to the Access DB
`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.
`java.sql.Connection` | `getConnection(javax.servlet.ServletContext context)` 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)` 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)` 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()` Gets the Database Name for the current instance
`java.lang.String` | `getMySQLDSN()` Gets the DSN for MySQLDB
`void` | `setAccessDBPath(java.lang.String accessDBPath)` Sets the path to the AccessDB
`void` | `setDbName(java.lang.String dbName)` Sets the Database Name for the current instance
`void` | `setMySQLDSN(java.lang.String mySQLDSN)` 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

### dbName

    private java.lang.String dbName

  Name of the database to be used

### accessDBPath

    private java.lang.String accessDBPath

  Path to the access DB

### mySQLDSN

    private java.lang.String mySQLDSN

  DSN for the MySql DB

Constructor Detail

### DBConnection

    public DBConnection()

Method Detail

### getConnection

    public 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.

  Returns:
    Connection - a connection to the specific database based on the configuration

### getConnection

    public java.sql.Connection getConnection(javax.servlet.ServletContext context)

  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.

  Parameters:
    `context` - ServletContext of the server requesting connection
  Returns:
    Connection - a connection to the database given in configuration file of the server.

### getConnectionByDSN

    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.

  Returns:
    Connection a connection to the MySQL database

### getConnection

    private java.sql.Connection getConnection(java.lang.String pathToDB)

  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.

  Parameters:
    `pathToDB` - - the path to the mdb file
  Returns:
    Connection - a connection to the Access database

### getAccessDBPath

    public java.lang.String getAccessDBPath()

  Gets the path to the Access DB

  Returns:
    String - path to the Access DB

### setAccessDBPath

    public void setAccessDBPath(java.lang.String accessDBPath)

  Sets the path to the AccessDB

  Parameters:
    `accessDBPath` - - path to the Access DB

### getDbName

    public java.lang.String getDbName()

  Gets the Database Name for the current instance

  Returns:
    String - the Database name

### setDbName

    public void setDbName(java.lang.String dbName)

  Sets the Database Name for the current instance

  Parameters:
    `dbName` -

### getMySQLDSN

    public java.lang.String getMySQLDSN()

  Gets the DSN for MySQLDB

  Returns:
    String - the DSN for MySQLDB

### setMySQLDSN

    public void setMySQLDSN(java.lang.String mySQLDSN)

  Sets the DSN for MySQLDB

  Parameters:
    `mySQLDSN` -

Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD