de.web.databasesupport.tools.database
Interface Database

All Known Implementing Classes:
SimpleDatabase

public interface Database

This interface declares basic functionality to access a database. It's possible to retrieve information on tables and columns within a table. E.g. testing if a specific table exists in the database or what columns exist in a specific table.
There is also functionality to send SQL statements directly to the database or to precompile often used statements for better performance.

See Also:
and the java.sql package for more detailed information on how to handle ResultSets.

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.
 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 closed.
 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.
 

Method Detail

open

public void open()
          throws java.lang.ClassNotFoundException,
                 java.sql.SQLException,
                 java.lang.InstantiationException,
                 java.lang.IllegalAccessException
Opens the connection to the database. Using the specified database and driver.

close

public void close()
           throws java.sql.SQLException,
                  NotConnectedException
Closes the connection to the database.

commit

public void commit()
            throws java.sql.SQLException,
                   NotConnectedException
Commits pending data to the 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.
Returns:
The precompiled statement.

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.
Parameters:
statement - The SQL satement to execute.
Returns:
The ResultSet returned from the database.

executeUpdate

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

getTablenames

public java.lang.String[] getTablenames()
                                 throws java.sql.SQLException,
                                        NotConnectedException
Returns names of all tables within the 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.
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.
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.
Parameters:
tableName - The table name.
Returns:
All column names in the table.

getColumnNames

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

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.
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.
Parameters:
tableName - The name of the table.
columnName - The name of the column.
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.
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.
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.
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.
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,
                        NotConnectedException
Tests if is closed.
Returns:
true if the database connection is closed, false otherwise.

getColumnCount

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

getColumnCount

public int getColumnCount(java.sql.ResultSet result)
                   throws java.sql.SQLException
Returns the column count of a ResultSet.
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.
Returns:
The table count.

getColumnNamesVector

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

getColumnNamesVector

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

getTablenamesVector

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