de.web.databasesupport.tools.database
Class SimpleDatabase

java.lang.Object
  |
  +--de.web.databasesupport.tools.database.SimpleDatabase
All Implemented Interfaces:
Database

public class SimpleDatabase
extends java.lang.Object
implements Database

Implemented Interface Database.


Field Summary
static int COLUMN_BUFFER_LENGTH
           
static int COLUMN_CHAR_OCTET_LENGTH
           
static int COLUMN_DATA_TYPE
           
static int COLUMN_DECIMAL_DIGITS
           
static int COLUMN_DEF
           
static int COLUMN_IS_NULLABLE
           
static int COLUMN_NAME
           
static int COLUMN_NULLABLE
           
static int COLUMN_NUM_PREC_RADIX
           
static int COLUMN_ORDINAL_POSITION
           
static int COLUMN_REMARKS
           
static int COLUMN_SIZE
           
static int COLUMN_SQL_DATA_TYPE
           
static int COLUMN_SQL_DATETIME_SUB
           
static int COLUMN_TYPE_NAME
           
static java.lang.String JDATA2_0_DRIVER
          Driver for an ODBC-Database.
static java.lang.String JDBC_ODBC_DRIVER
          Driver for an JDBC-ODBC-Database like MS Access.
static int TABLE_CAT
           
static int TABLE_NAME
           
static int TABLE_REMARKS
           
static int TABLE_SCHEM
           
static int TABLE_TYPE
           
 
Constructor Summary
SimpleDatabase(java.lang.String jdbcDriver, java.lang.String jdbcConnection)
          Constructor An URL for the JDBC:ODBC-Driver can look like "jdbc:odbc:YourDB".
SimpleDatabase(java.lang.String jdbcDriver, java.lang.String jdbcConnection, java.util.Properties prop)
          Constructor An URL for the JDBC:ODBC-Driver can look like "jdbc:odbc:YourDB".
SimpleDatabase(java.lang.String jdbcDriver, java.lang.String jdbcConnection, java.lang.String username, java.lang.String password)
          Constructor An URL for the JDBC:ODBC-Driver can look like "jdbc:odbc:YourDB".
 
Method Summary
 void close()
          Closes the connection to the database.
 boolean columnExists(java.lang.String tableName, int columnIndex)
          Tests if a column exists.
 boolean columnExists(java.lang.String tableName, java.lang.String columnName)
          Tests if a column exists.
 void commit()
          Commits pending data to the database.
 java.sql.ResultSet executeQuery(java.lang.String statement)
          Executes an Query from a SQL statement.
 void executeUpdate(java.lang.String statement)
          Executes an Update statement.
 int getColumnCount(java.sql.ResultSet result)
          Returns the column count of a ResultSet.
 int getColumnCount(java.lang.String tableName)
          Returns the column count of the table.
 java.sql.ResultSet getColumnDescription(java.lang.String tableName, int columnIndex)
          Returns a ResultSet containing a description of the column.
 java.sql.ResultSet getColumnDescription(java.lang.String tableName, java.lang.String columnName)
          Returns a ResultSet containing a description of the column.
 java.sql.ResultSet getColumnDescriptions(java.lang.String tableName)
          Returns a ResultSet containing a description of all columns in table.
 java.lang.String[] getColumnNames(java.sql.ResultSet result)
          Returns the names of the Columns in a ResultSet.
 java.lang.String[] getColumnNames(java.lang.String tableName)
          Returns all column names for the table.
 java.util.Vector getColumnNamesVector(java.sql.ResultSet result)
          Returns the names of the Columns in a ResultSet.
 java.util.Vector getColumnNamesVector(java.lang.String tableName)
          Returns all column names for the table.
 java.sql.Connection getConnection()
          Returns the connection.
protected  java.lang.String getDriver()
          Returns the driver.
 int getTableCount()
          Returns the table count of the database.
 java.sql.ResultSet getTableDescription(java.lang.String tableName)
          Returns a ResultSet containing description of a table.
 java.sql.ResultSet getTableDescriptions()
          Returns a ResultSet containing the descriptions of all tables.
 java.lang.String[] getTablenames()
          Returns names of all tables within the database.
 java.util.Vector getTablenamesVector()
          Returns names of all tables within the database.
 boolean isClosed()
          Tests if is opened.
 void open()
          Opens the connection to the database.
 java.sql.PreparedStatement precompile(java.lang.String statement)
          Precompiles a SQL statement.
 boolean tableExists(java.lang.String tableName)
          Tests if a table exists.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_CAT

public static final int TABLE_CAT

TABLE_SCHEM

public static final int TABLE_SCHEM

TABLE_NAME

public static final int TABLE_NAME

TABLE_TYPE

public static final int TABLE_TYPE

TABLE_REMARKS

public static final int TABLE_REMARKS

COLUMN_NAME

public static final int COLUMN_NAME

COLUMN_DATA_TYPE

public static final int COLUMN_DATA_TYPE

COLUMN_TYPE_NAME

public static final int COLUMN_TYPE_NAME

COLUMN_SIZE

public static final int COLUMN_SIZE

COLUMN_BUFFER_LENGTH

public static final int COLUMN_BUFFER_LENGTH

COLUMN_DECIMAL_DIGITS

public static final int COLUMN_DECIMAL_DIGITS

COLUMN_NUM_PREC_RADIX

public static final int COLUMN_NUM_PREC_RADIX

COLUMN_NULLABLE

public static final int COLUMN_NULLABLE

COLUMN_REMARKS

public static final int COLUMN_REMARKS

COLUMN_DEF

public static final int COLUMN_DEF

COLUMN_SQL_DATA_TYPE

public static final int COLUMN_SQL_DATA_TYPE

COLUMN_SQL_DATETIME_SUB

public static final int COLUMN_SQL_DATETIME_SUB

COLUMN_CHAR_OCTET_LENGTH

public static final int COLUMN_CHAR_OCTET_LENGTH

COLUMN_ORDINAL_POSITION

public static final int COLUMN_ORDINAL_POSITION

COLUMN_IS_NULLABLE

public static final int COLUMN_IS_NULLABLE

JDATA2_0_DRIVER

public static final java.lang.String JDATA2_0_DRIVER
Driver for an ODBC-Database. Useable for an network database.

JDBC_ODBC_DRIVER

public static final java.lang.String JDBC_ODBC_DRIVER
Driver for an JDBC-ODBC-Database like MS Access. Not usable for an network Database.
Constructor Detail

SimpleDatabase

public SimpleDatabase(java.lang.String jdbcDriver,
                      java.lang.String jdbcConnection)
Constructor An URL for the JDBC:ODBC-Driver can look like "jdbc:odbc:YourDB". For the JData2_0_Driver use the Constructor with username and password.
Parameters:
jdbcDriver - The driver to connect to the database.
jdbcConnection - The url of the connection.

SimpleDatabase

public SimpleDatabase(java.lang.String jdbcDriver,
                      java.lang.String jdbcConnection,
                      java.lang.String username,
                      java.lang.String password)
Constructor An URL for the JDBC:ODBC-Driver can look like "jdbc:odbc:YourDB". An URL for the JData2_0 - ODBC-Driver can look like "jdbc:JDataConnect://127.0.0.1/YourDB".
Parameters:
jdbcDriver - The driver to connect to the database.
jdbcConnection - The url of the connection.
username - The name of the user.
password - The password of the user.

SimpleDatabase

public SimpleDatabase(java.lang.String jdbcDriver,
                      java.lang.String jdbcConnection,
                      java.util.Properties prop)
Constructor An URL for the JDBC:ODBC-Driver can look like "jdbc:odbc:YourDB". An URL for the JData2_0 - ODBC-Driver can look like "jdbc:JDataConnect://127.0.0.1/YourDB".
Parameters:
jdbcDriver - The driver to connect to the database.
jdbcConnection - The url of the connection.
username - The name of the user.
password - The password of the user.
Method Detail

open

public void open()
          throws java.sql.SQLException,
                 java.lang.ClassNotFoundException,
                 java.lang.InstantiationException,
                 java.lang.IllegalAccessException
Opens the connection to the database. Using the specified database and driver. AutoCommit is set to false.
Specified by:
open in interface Database

close

public void close()
           throws java.sql.SQLException,
                  NotConnectedException
Closes the connection to the database.
Specified by:
close in interface Database

commit

public void commit()
            throws java.sql.SQLException,
                   NotConnectedException
Commits pending data to the database.
Specified by:
commit in interface Database

precompile

public java.sql.PreparedStatement precompile(java.lang.String statement)
                                      throws java.sql.SQLException,
                                             NotConnectedException
Precompiles a SQL statement. Increases performance for frequently used SQL statements. A openened database connection is needed.
Specified by:
precompile in interface Database
Returns:
The precompiled statement.

executeUpdate

public void executeUpdate(java.lang.String statement)
                   throws java.sql.SQLException,
                          NotConnectedException
Executes an Update statement. A opened database connection is needed.
Specified by:
executeUpdate in interface Database
Parameters:
statement - The SQL satement to execute.

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String statement)
                                throws java.sql.SQLException,
                                       NotConnectedException
Executes an Query from a SQL statement. A opened database connection is needed.
Specified by:
executeQuery in interface Database
Parameters:
statement - The SQL satement to execute.
Returns:
The ResultSet returned from the database.

getTablenames

public java.lang.String[] getTablenames()
                                 throws java.sql.SQLException,
                                        NotConnectedException
Returns names of all tables within the database.
Specified by:
getTablenames in interface Database
Returns:
The names of all tables.

getTablenamesVector

public java.util.Vector getTablenamesVector()
                                     throws java.sql.SQLException,
                                            NotConnectedException
Returns names of all tables within the database.
Specified by:
getTablenamesVector in interface Database
Returns:
The names of all tables.

getTableDescription

public java.sql.ResultSet getTableDescription(java.lang.String tableName)
                                       throws java.sql.SQLException,
                                              NotConnectedException
Returns a ResultSet containing description of a table.
Specified by:
getTableDescription in interface Database
Parameters:
tableName - The name of the table.
Returns:
The description for the table.

getTableDescriptions

public java.sql.ResultSet getTableDescriptions()
                                        throws java.sql.SQLException,
                                               NotConnectedException
Returns a ResultSet containing the descriptions of all tables.
Specified by:
getTableDescriptions in interface Database
Returns:
The description of all tables.

getColumnNames

public java.lang.String[] getColumnNames(java.lang.String tableName)
                                  throws java.sql.SQLException,
                                         NotConnectedException
Returns all column names for the table.
Specified by:
getColumnNames in interface Database
Parameters:
tableName - The table name.
Returns:
All column names in the table.

getColumnNamesVector

public java.util.Vector getColumnNamesVector(java.lang.String tableName)
                                      throws java.sql.SQLException,
                                             NotConnectedException
Returns all column names for the table.
Specified by:
getColumnNamesVector in interface Database
Parameters:
tableName - The table name.
Returns:
All column names in the table.

getColumnDescription

public java.sql.ResultSet getColumnDescription(java.lang.String tableName,
                                               java.lang.String columnName)
                                        throws java.sql.SQLException,
                                               NotConnectedException
Returns a ResultSet containing a description of the column.
Specified by:
getColumnDescription in interface Database
Parameters:
tableName - The name of the table.
columnName - The name of the column.
Returns:
The description.

getColumnDescription

public java.sql.ResultSet getColumnDescription(java.lang.String tableName,
                                               int columnIndex)
                                        throws java.sql.SQLException,
                                               NotConnectedException,
                                               java.lang.IndexOutOfBoundsException
Returns a ResultSet containing a description of the column.
Specified by:
getColumnDescription in interface Database
Parameters:
tableName - The name of the table.
columnIndex - The index of the column must be greater 0.
Returns:
The description.

getColumnDescriptions

public java.sql.ResultSet getColumnDescriptions(java.lang.String tableName)
                                         throws java.sql.SQLException,
                                                NotConnectedException
Returns a ResultSet containing a description of all columns in table.
Specified by:
getColumnDescriptions in interface Database
Parameters:
tableName - The name of the table.
Returns:
The description.

tableExists

public boolean tableExists(java.lang.String tableName)
                    throws java.sql.SQLException,
                           NotConnectedException
Tests if a table exists.
Specified by:
tableExists in interface Database
Parameters:
tableName - The name of the table.
Returns:
true if the table exists, false otherwise.

columnExists

public boolean columnExists(java.lang.String tableName,
                            java.lang.String columnName)
                     throws java.sql.SQLException,
                            NotConnectedException
Tests if a column exists.
Specified by:
columnExists in interface Database
Parameters:
tableName - The name of the table.
columnName - The name of the column.
Returns:
true if the column exists in the table, false otherwise.

columnExists

public boolean columnExists(java.lang.String tableName,
                            int columnIndex)
                     throws java.sql.SQLException,
                            NotConnectedException
Tests if a column exists.
Specified by:
columnExists in interface Database
Parameters:
tableName - The name of the table.
columnIndex - The index of the column.
Returns:
true if the column exists in the table, false otherwise.

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Tests if is opened.
Specified by:
isClosed in interface Database
Returns:
true if the database connection is opened, false otherwise.

getColumnCount

public int getColumnCount(java.lang.String tableName)
                   throws java.sql.SQLException,
                          NotConnectedException
Returns the column count of the table.
Specified by:
getColumnCount in interface Database
Parameters:
tableName - The name of the table.
Returns:
The column count.

getColumnNames

public java.lang.String[] getColumnNames(java.sql.ResultSet result)
                                  throws java.sql.SQLException
Returns the names of the Columns in a ResultSet.
Specified by:
getColumnNames in interface Database
Parameters:
result - The ResultSet to examine.
Returns:
All column names.

getColumnNamesVector

public java.util.Vector getColumnNamesVector(java.sql.ResultSet result)
                                      throws java.sql.SQLException
Returns the names of the Columns in a ResultSet.
Specified by:
getColumnNamesVector in interface Database
Parameters:
result - The ResultSet to examine.
Returns:
All column names.

getColumnCount

public int getColumnCount(java.sql.ResultSet result)
                   throws java.sql.SQLException
Returns the column count of a ResultSet.
Specified by:
getColumnCount in interface Database
Parameters:
tableName - The name of the table.
Returns:
The column count.

getTableCount

public int getTableCount()
                  throws java.sql.SQLException,
                         NotConnectedException
Returns the table count of the database.
Specified by:
getTableCount in interface Database
Returns:
The table count.

getConnection

public java.sql.Connection getConnection()
Returns the connection.
Returns:
The connection.

getDriver

protected java.lang.String getDriver()
Returns the driver.
Returns:
The driver.