org.gswing.components.common.db
Class DbAccess

java.lang.Object
  extended by org.gswing.components.common.db.DbAccess
Direct Known Subclasses:
DbReadAccess

public class DbAccess
extends Object

Purpose: Creates and maintains a JDBC connection with a database.


Constructor Summary
DbAccess(String url, String dbName, String userName)
          Constructor.
DbAccess(String url, String dbName, String userName, String password)
          Constructor.
 
Method Summary
 void closeConnection()
          Close the database connection.
protected  Statement createStatement()
          Create standard statement with a query timeout of 10 seconds.
protected  Connection getConnection()
          Get the JDBC connection to this database.
 String getDatabaseName()
          Get the name of this database.
 int getNumberOfTables()
          Counts number of tables in database.
 String getPassword()
          Get the password for this database
 Vector getTableList()
          Get the list of tables in this database.
 boolean hasValidConnection()
          Do we have a valid database connection?
 boolean isConnected()
          Determine database connection status;
 boolean setDriverClassName(String driver)
          Set the driver class name.
 void setPassword(String password)
          Set the database password.
 boolean tableExists(String tableName)
          Check whether a particular table exists in this database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbAccess

public DbAccess(String url,
                String dbName,
                String userName,
                String password)
Constructor.

Parameters:
url - The URL of this database connection.
dbName - The database name or catalogue.
userName - The database user name.
password - The database password.

DbAccess

public DbAccess(String url,
                String dbName,
                String userName)
Constructor.

Parameters:
url - The URL of this database connection.
dbName - The database name or catalogue.
userName - The database user name.
Method Detail

tableExists

public boolean tableExists(String tableName)
Check whether a particular table exists in this database.

Parameters:
tableName - The name of the table to check.
Returns:
Whether this table exists.

getConnection

protected Connection getConnection()
Get the JDBC connection to this database.

Returns:
The JDBC connection to this database.

closeConnection

public void closeConnection()
Close the database connection.


isConnected

public boolean isConnected()
Determine database connection status;


createStatement

protected Statement createStatement()
                             throws SQLException
Create standard statement with a query timeout of 10 seconds.

Returns:
The SQL statement.
Throws:
SQLException

getPassword

public String getPassword()
Get the password for this database

Returns:
The password for this database.

setDriverClassName

public boolean setDriverClassName(String driver)
Set the driver class name.

Parameters:
driver - The driver class name.
Returns:
Whether the class name was successfully set.

setPassword

public void setPassword(String password)
Set the database password.

Parameters:
password - The password to set.

getNumberOfTables

public int getNumberOfTables()
Counts number of tables in database.

Returns:
Number of tables.

getTableList

public Vector getTableList()
Get the list of tables in this database.

Returns:
The list of table names.

getDatabaseName

public String getDatabaseName()
Get the name of this database.

Returns:
The name of database.

hasValidConnection

public boolean hasValidConnection()
Do we have a valid database connection?

Returns:
True if there is a valid database connnection


Copyright © 2008. All Rights Reserved.