All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class dbgeneric.DatabaseAccess

java.lang.Object
   |
   +----dbgeneric.DatabaseAccess

public class DatabaseAccess
extends Object
implements Serializable

Base class for database accessor classes.

Provides a set of common database functions.
These include making connections and running queries.


Variable Index

 o _con
This use of a static ConnectionManager allows all the extended classes to use the same pool of connections to the database.
 o debug
 o queryStatement

Constructor Index

 o DatabaseAccess()
Constructor which loads properties in from the default file called "db.properties".
 o DatabaseAccess(Properties)
Constructor with Properties.

Method Index

 o catchEx(Exception)
General last ditch exception catcher.
 o connect()
Gets a valid connection to the database from the Connection Manager and stores it in _con.
 o disconnect()
Puts our connection back into the ConnectionManager pool.
 o doUpdateQuery(String)
Executes an update/insert query in the database.
Note we must be connect to the database before making this call.
 o executeQuery(String)
Executes a query in the database which returns a Resultset.
Note we must be connect to the database before making this call.
 o getError()
Gets the error string.
 o setError(String)
Sets the error string.

Variables

 o _con
 public Connection _con
This use of a static ConnectionManager allows all the extended classes to use the same pool of connections to the database. This is very effecient. The only downside is that it effectively prevents connections to multiple databases. To achieve multiple databases, this class would have to be copied to a different name and hence give multiple connection pools

 o queryStatement
 public Statement queryStatement
 o debug
 public static final boolean debug

Constructors

 o DatabaseAccess
 public DatabaseAccess()
Constructor which loads properties in from the default file called "db.properties". This is only done on the first call of this constructor. Later calls will use the existing connection pool.

 o DatabaseAccess
 public DatabaseAccess(Properties props)
Constructor with Properties.
Sets the values used to connect to the database to be different via the user defined Properties.
Includes defining the proxy, registering the driver etc

Methods

 o setError
 public void setError(String error)
Sets the error string.

 o getError
 public String getError()
Gets the error string.

 o catchEx
 public void catchEx(Exception e)
General last ditch exception catcher.
Simply logs the error.

 o connect
 public boolean connect()
Gets a valid connection to the database from the Connection Manager and stores it in _con.

 o disconnect
 public boolean disconnect() throws SQLException
Puts our connection back into the ConnectionManager pool.

 o doUpdateQuery
 public synchronized boolean doUpdateQuery(String dbQuery)
Executes an update/insert query in the database.
Note we must be connect to the database before making this call.

 o executeQuery
 public synchronized ResultSet executeQuery(String query) throws SQLException
Executes a query in the database which returns a Resultset.
Note we must be connect to the database before making this call. This call is synchronised to limit the number of executing statements to one per DatabaseAccess instantiation.


All Packages  Class Hierarchy  This Package  Previous  Next  Index