de.fh_mannheim.mm.dms.framework
Class ConnectionManager

java.lang.Object
  extended byde.fh_mannheim.mm.dms.framework.ConnectionManager
Direct Known Subclasses:
ContentConnectionManager

public class ConnectionManager
extends java.lang.Object

ConnectionManager connects to database.

Version:
$Revision: 1.32 $
Author:
Jan Löffler, mail@jlsoft.de

Constructor Summary
ConnectionManager(Config cfg)
          Constructor.
 
Method Summary
 void checkConnection()
          Connects to database, if not connection exists.
 void closeConnection()
          Closes connection to database.
 void closePreparedStatement(java.sql.PreparedStatement ps)
          Closes a prepared statement.
 void closeResultSet(java.sql.ResultSet rs)
          Closes a resultset.
 void closeResultSet(java.sql.ResultSet rs, boolean bCloseStatement)
          Closes a resultset.
 void commit()
          Stores a transaction with commit.
 java.sql.ResultSet executeQuery(java.lang.String strSQL)
          Executes a query command to the database.
 boolean executeQueryGetBool(java.lang.String strFieldname, java.lang.String strSQL)
          Executes a query command to the database and returns an boolean value.
 FormattedDate executeQueryGetDate(java.lang.String strFieldname, java.lang.String strSQL)
          Executes a query command to the database and returns an date value.
 double executeQueryGetDouble(java.lang.String strFieldname, java.lang.String strSQL)
          Executes a query command to the database and returns an double value.
 int executeQueryGetInt(java.lang.String strFieldname, java.lang.String strSQL)
          Executes a query command to the database and returns an integer value.
 java.lang.String executeQueryGetString(java.lang.String strFieldname, java.lang.String strSQL)
          Executes a query command to the database and returns an integer value.
 boolean executeUpdate(java.lang.String strSQL)
          Executes an update command to the database.
 java.lang.String formatBool(boolean bValue)
          Format a boolean value for a database command.
 java.lang.String formatDate()
          Format the actual date for a database command.
 java.lang.String formatDate(FormattedDate date)
          Format a date for a database command.
 java.lang.String formatDouble(double dValue)
          Format an double value for a database command.
 java.lang.String formatInteger(int nValue)
          Format an integer value for a database command.
 java.lang.String formatString(java.lang.String strText)
          Format a string for a database command.
 java.sql.PreparedStatement getPreparedStatement(java.lang.String strSQL)
          Get a prepared statement.
 void openConnection()
          Connects to database.
 void optimizeTable(java.lang.String strTablename)
          Optimizes a database table.
 void rollback()
          Cancels a transaction with rollback.
 void startTransaction()
          Starts a transaction by setting autocommit to zero.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager(Config cfg)
Constructor.

Parameters:
cfg - Config
Method Detail

closeConnection

public void closeConnection()
Closes connection to database.


closePreparedStatement

public void closePreparedStatement(java.sql.PreparedStatement ps)
Closes a prepared statement.

Parameters:
ps - The PreparedStatement which should be closed

closeResultSet

public void closeResultSet(java.sql.ResultSet rs)
Closes a resultset.

Parameters:
rs - The ResultSet which should be closed

closeResultSet

public void closeResultSet(java.sql.ResultSet rs,
                           boolean bCloseStatement)
Closes a resultset.

Parameters:
rs - The ResultSet which should be closed
bCloseStatement - Close statement too

commit

public void commit()
Stores a transaction with commit.


executeQuery

public java.sql.ResultSet executeQuery(java.lang.String strSQL)
Executes a query command to the database.

Parameters:
strSQL - SQL string
Returns:
ResultSet

executeQueryGetInt

public int executeQueryGetInt(java.lang.String strFieldname,
                              java.lang.String strSQL)
Executes a query command to the database and returns an integer value.

Parameters:
strFieldname - Name of the field for return value
strSQL - SQL string
Returns:
Integer value

executeQueryGetDate

public FormattedDate executeQueryGetDate(java.lang.String strFieldname,
                                         java.lang.String strSQL)
Executes a query command to the database and returns an date value.

Parameters:
strFieldname - Name of the field for return value
strSQL - SQL string
Returns:
Date value

executeQueryGetDouble

public double executeQueryGetDouble(java.lang.String strFieldname,
                                    java.lang.String strSQL)
Executes a query command to the database and returns an double value.

Parameters:
strFieldname - Name of the field for return value
strSQL - SQL string
Returns:
Double value

executeQueryGetBool

public boolean executeQueryGetBool(java.lang.String strFieldname,
                                   java.lang.String strSQL)
Executes a query command to the database and returns an boolean value.

Parameters:
strFieldname - Name of the field for return value
strSQL - SQL string
Returns:
Boolean value

executeQueryGetString

public java.lang.String executeQueryGetString(java.lang.String strFieldname,
                                              java.lang.String strSQL)
Executes a query command to the database and returns an integer value.

Parameters:
strFieldname - Name of the field for return value
strSQL - SQL string
Returns:
String value

executeUpdate

public boolean executeUpdate(java.lang.String strSQL)
Executes an update command to the database.

Parameters:
strSQL - SQL string
Returns:
true, if successful

formatBool

public java.lang.String formatBool(boolean bValue)
Format a boolean value for a database command.

Parameters:
bValue - True or false
Returns:
bool string

formatDate

public java.lang.String formatDate()
Format the actual date for a database command.

Returns:
date string

formatDate

public java.lang.String formatDate(FormattedDate date)
Format a date for a database command.

Parameters:
date -
Returns:
date string

formatDouble

public java.lang.String formatDouble(double dValue)
Format an double value for a database command.

Parameters:
dValue - Double
Returns:
string

formatInteger

public java.lang.String formatInteger(int nValue)
Format an integer value for a database command.

Parameters:
nValue - Integer
Returns:
string

formatString

public java.lang.String formatString(java.lang.String strText)
Format a string for a database command.

Parameters:
strText - Text
Returns:
string

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.String strSQL)
Get a prepared statement.

Parameters:
strSQL - SQL string
Returns:
New statement

openConnection

public void openConnection()
Connects to database.


checkConnection

public void checkConnection()
Connects to database, if not connection exists.


optimizeTable

public void optimizeTable(java.lang.String strTablename)
Optimizes a database table.

Parameters:
strTablename - Name of the table

rollback

public void rollback()
Cancels a transaction with rollback.


startTransaction

public void startTransaction()
Starts a transaction by setting autocommit to zero.