ccl.util
Class DBUtil

java.lang.Object
  |
  +--ccl.util.DBUtil

public class DBUtil
extends java.lang.Object

This class provides convenience methods to access a database via jdbc.


Nested Class Summary
static class DBUtil.DBConstant
          This class is used to indicate the database currently used.
 
Field Summary
static DBUtil.DBConstant INSTANTDB
          Constant to indicate an InstantDB database.
static DBUtil.DBConstant POSTGRESQL
          Constant to indicate a PostgreSQL database.
static DBUtil.DBConstant SYBASE
          Constant to indicate a Sybase database.
 
Constructor Summary
DBUtil()
           
 
Method Summary
static void close(java.sql.Statement statement_)
          Closes the given statement and the connection it belongs to.
static void copyRecord(java.sql.ResultSet rsRecord_, java.util.Hashtable htRecord_)
          Copies all columns from one record into a hashtable.
static java.sql.Connection createConnection(DBUtil.DBConstant database, java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String applicationname, java.lang.String clienthost)
          Creates a database connection.
static java.sql.Connection createIDBConnection(java.lang.String sDatabaseFile)
          Creates a instantdb database connection.
static java.sql.Statement createIDBStatement(java.lang.String sDatabaseFile)
          Creates a jsbc statement for the given instantdb database.
static java.sql.Connection createPGConnection(java.lang.String sDatabaseName)
          Creates a PostgreSQL database connection on the local host and the current user given the database name.
static void deleteTable(java.sql.Connection connection_, java.lang.String sTableName_)
          Deletes the given table.
static java.util.Vector getIDBUserTables(java.lang.String sDatabaseFile)
          Gets the list of InstantDB user tables.
static java.lang.String getNextId(java.sql.Statement statement, java.lang.String sTableName)
          Gets the next id for a given table.
static java.util.Vector getUserTables(java.sql.Connection connection)
          Gets the list of user tables.
static void initializeDB(DBUtil.DBConstant database)
          Initializes a database for either InstantDB, Sybase or whatsoever.
static void initializeDB(java.lang.String sDriver)
          Initializes a database with the given driver.
static void initializeIDB()
          Initializes an InstantDB database.
static void initializePGDB()
          Initializes a PostgreSQL database.
static void initializeSybDB()
          Initializes a Sybase database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANTDB

public static final DBUtil.DBConstant INSTANTDB
Constant to indicate an InstantDB database.


SYBASE

public static final DBUtil.DBConstant SYBASE
Constant to indicate a Sybase database.


POSTGRESQL

public static final DBUtil.DBConstant POSTGRESQL
Constant to indicate a PostgreSQL database.

Constructor Detail

DBUtil

public DBUtil()
Method Detail

initializeIDB

public static void initializeIDB()
                          throws java.lang.Exception
Initializes an InstantDB database.

Throws:
java.lang.Exception - if loading the driver class fails.

initializePGDB

public static void initializePGDB()
                           throws java.lang.Exception
Initializes a PostgreSQL database.

Throws:
java.lang.Exception - if loading the driver class fails.

initializeSybDB

public static void initializeSybDB()
                            throws java.lang.Exception
Initializes a Sybase database.

Throws:
java.lang.Exception - if loading the driver class fails.

initializeDB

public static void initializeDB(java.lang.String sDriver)
                         throws java.lang.Exception
Initializes a database with the given driver.

Throws:
java.lang.Exception - if loading the driver class fails.

initializeDB

public static void initializeDB(DBUtil.DBConstant database)
                         throws java.lang.Exception
Initializes a database for either InstantDB, Sybase or whatsoever.

Throws:
java.lang.Exception - if loading the driver class fails.

createIDBConnection

public static java.sql.Connection createIDBConnection(java.lang.String sDatabaseFile)
                                               throws java.sql.SQLException
Creates a instantdb database connection.

Throws:
java.sql.SQLException - if creating connection fails.

createPGConnection

public static java.sql.Connection createPGConnection(java.lang.String sDatabaseName)
                                              throws java.sql.SQLException
Creates a PostgreSQL database connection on the local host and the current user given the database name.

Throws:
java.sql.SQLException - if creating connection fails.

createConnection

public static java.sql.Connection createConnection(DBUtil.DBConstant database,
                                                   java.lang.String url,
                                                   java.lang.String user,
                                                   java.lang.String password,
                                                   java.lang.String applicationname,
                                                   java.lang.String clienthost)
                                            throws java.sql.SQLException
Creates a database connection.

Throws:
java.sql.SQLException - if creating connection fails.

createIDBStatement

public static java.sql.Statement createIDBStatement(java.lang.String sDatabaseFile)
                                             throws java.sql.SQLException
Creates a jsbc statement for the given instantdb database.

Throws:
java.sql.SQLException - if creating connection fails.

close

public static void close(java.sql.Statement statement_)
                  throws java.sql.SQLException
Closes the given statement and the connection it belongs to.

Throws:
java.sql.SQLException - if anything goes wrong.

deleteTable

public static void deleteTable(java.sql.Connection connection_,
                               java.lang.String sTableName_)
                        throws java.sql.SQLException
Deletes the given table.

Throws:
java.sql.SQLException - if anything goes wrong.

getIDBUserTables

public static java.util.Vector getIDBUserTables(java.lang.String sDatabaseFile)
                                         throws java.lang.Exception
Gets the list of InstantDB user tables.

Throws:
java.lang.Exception - if anything goes wrong.

getUserTables

public static java.util.Vector getUserTables(java.sql.Connection connection)
                                      throws java.lang.Exception
Gets the list of user tables.

Throws:
java.lang.Exception - if anything goes wrong.

copyRecord

public static void copyRecord(java.sql.ResultSet rsRecord_,
                              java.util.Hashtable htRecord_)
                       throws java.sql.SQLException
Copies all columns from one record into a hashtable. The column names are used as keys in the hashtable.

Parameters:
rsRecord_ - The result set pointing via next to the current record.
htRecord_ - The hashtable used to copy over the record.
Throws:
java.sql.SQLException - if anything goes wrong.

getNextId

public static java.lang.String getNextId(java.sql.Statement statement,
                                         java.lang.String sTableName)
                                  throws java.sql.SQLException
Gets the next id for a given table. The table needs a column with name "id".

Throws:
java.sql.SQLException - if anything goes wrong.