semorg.sql.access
Class DBAccess

java.lang.Object
  extended by semorg.sql.access.DBAccess

public class DBAccess
extends Object

Implements the access to the database. Therefor this class fulfills the following functions:

Hint: The user semorg which uses the application to access the database must exist already and must have the appropriate rights.


Field Summary
private static String chosenDataBaseDriver
           
private static String chosenDriverURL
           
private  Connection connection
           
private static String databaseName
           
private static String databasePassword
           
private static String databaseUsername
           
static DBAccess dbAccess
          Provides a static db access.
private static String mysqlURL
           
 
Constructor Summary
private DBAccess()
          This method tries to connect to the catalog husemorg and if that fails it tries to create it.
 
Method Summary
private  void createDatabaseAndConnect()
          Creates a connection to the MySQL database and creates the catalog for the application if it does not exist.
private  void createTables()
           
 PreparedStatement getPreparedStatement(String sqlString)
          Returns for a given SQL query as a string the appropriate PreparedStatement instance.
 Statement getStatement()
          Returns for a given SQL query as a string the appropriate Statement instance.
static void init()
          Initiates the static database access attribute dbAccess.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbAccess

public static DBAccess dbAccess
Provides a static db access.


chosenDataBaseDriver

private static String chosenDataBaseDriver

chosenDriverURL

private static String chosenDriverURL

databaseName

private static String databaseName

mysqlURL

private static String mysqlURL

databaseUsername

private static String databaseUsername

databasePassword

private static String databasePassword

connection

private Connection connection
Constructor Detail

DBAccess

private DBAccess()
          throws SQLException,
                 ClassNotFoundException
This method tries to connect to the catalog husemorg and if that fails it tries to create it.

Throws:
SQLException - if the connection to the database can not be created or the creating of the catalog and the tables fails.
ClassNotFoundException - if the database driver can not be loaded.
See Also:
createDatabaseAndConnect()
Method Detail

createDatabaseAndConnect

private void createDatabaseAndConnect()
                               throws SQLException
Creates a connection to the MySQL database and creates the catalog for the application if it does not exist. Finally it connects to the new created catalog.

Throws:
SQLException - if the creation, execution or closing of the Statement fails.

createTables

private void createTables()
                   throws SQLException
Throws:
SQLException

init

public static void init()
                 throws ClassNotFoundException,
                        SQLException
Initiates the static database access attribute dbAccess.

Throws:
ClassNotFoundException
SQLException

getPreparedStatement

public PreparedStatement getPreparedStatement(String sqlString)
                                       throws SQLException
Returns for a given SQL query as a string the appropriate PreparedStatement instance.

Parameters:
sqlString - the SQL query as a String.
Throws:
SQLException

getStatement

public Statement getStatement()
                       throws SQLException
Returns for a given SQL query as a string the appropriate Statement instance.

Throws:
SQLException