com.partnersoft.io.sql
Class DatabaseConnection

java.lang.Object
  extended by com.partnersoft.io.sql.DatabaseConnection

public class DatabaseConnection
extends java.lang.Object

A wrapper around a standard Java SQL Connection. Uses DatabaseConnectionConfig to configure; supports resetting the connection, and has lots of convenience functions.

Author:
Paul Reavis Copyright 2003 Partner Software, Inc.

Constructor Summary
DatabaseConnection(DatabaseConnectionConfig config)
           
 
Method Summary
 void close()
           
 void connect()
           
 java.sql.Statement createReadOnlyStatement()
           
 DatabaseConnectionConfig getConfig()
           
 java.sql.Connection getConnection()
           
 void insertOrUpdate(java.lang.String table, java.lang.String keyField, Naming values)
          A convenience method that updates a single table using the given values and key field.
 java.util.ArrayList listCatalogs()
           
 java.util.ArrayList listColumns(java.lang.String tableName)
           
 java.util.ArrayList listSchemas()
           
 Naming listTableOwners()
           
 java.util.ArrayList listTables()
           
 java.util.ArrayList oneColumnQuery(java.lang.String query)
          Runs the given query and returns the result, which is assumed to be a single column, as an ArrayList.
 java.lang.String oneFieldQuery(java.lang.String query)
          Runs the given query and returns the result, which is assumed to be a single value (1 row, 1 column).
 Naming oneRowQuery(java.lang.String query)
          Runs the given query and returns the result, which is assumed to be a single row, as a Naming.
 java.sql.PreparedStatement prepareStatement(java.lang.String query)
           
 void runScript(java.lang.String query)
          Runs some kind of update query; doesn't return anything.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseConnection

public DatabaseConnection(DatabaseConnectionConfig config)
Method Detail

connect

public void connect()
             throws java.sql.SQLException
Throws:
java.sql.SQLException

getConfig

public DatabaseConnectionConfig getConfig()

getConnection

public java.sql.Connection getConnection()

createReadOnlyStatement

public java.sql.Statement createReadOnlyStatement()
                                           throws java.sql.SQLException
Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String query)
                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

oneFieldQuery

public java.lang.String oneFieldQuery(java.lang.String query)
                               throws java.sql.SQLException
Runs the given query and returns the result, which is assumed to be a single value (1 row, 1 column).

Throws:
java.sql.SQLException

oneRowQuery

public Naming oneRowQuery(java.lang.String query)
                   throws java.sql.SQLException
Runs the given query and returns the result, which is assumed to be a single row, as a Naming.

Throws:
java.sql.SQLException

oneColumnQuery

public java.util.ArrayList oneColumnQuery(java.lang.String query)
                                   throws java.sql.SQLException
Runs the given query and returns the result, which is assumed to be a single column, as an ArrayList.

Throws:
java.sql.SQLException

runScript

public void runScript(java.lang.String query)
               throws java.sql.SQLException
Runs some kind of update query; doesn't return anything.

Throws:
java.sql.SQLException

listTables

public java.util.ArrayList listTables()
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

listTableOwners

public Naming listTableOwners()
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

listCatalogs

public java.util.ArrayList listCatalogs()
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

listSchemas

public java.util.ArrayList listSchemas()
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

listColumns

public java.util.ArrayList listColumns(java.lang.String tableName)
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

insertOrUpdate

public void insertOrUpdate(java.lang.String table,
                           java.lang.String keyField,
                           Naming values)
                    throws java.sql.SQLException
A convenience method that updates a single table using the given values and key field. First it verifies that a record exists for the given key field value; if it does it does an update with the given values; otherwise it does an insert.

Throws:
java.sql.SQLException