edu.indiana.util.db
Class DBTools

java.lang.Object
  extended by edu.indiana.util.db.DBTools

public class DBTools
extends java.lang.Object

Contains useful static methods for using a database.


Field Summary
static java.lang.reflect.Method RESULTSET_DOT_GETINT
           
static java.lang.reflect.Method RESULTSET_DOT_GETSTRING
           
 
Constructor Summary
DBTools()
           
 
Method Summary
static boolean closeAll(java.sql.Connection connectionObject, java.sql.Statement statementObject)
          This method closes a conection and statement
static boolean closeAll(java.sql.Statement statementObject)
          This method closes a conection and statement
static boolean closeResultSet(java.sql.ResultSet resultSet)
          This method closes a JDBC resultset
static boolean closeSQLConnection(java.sql.Connection connectionObject)
          This method closes a JDBC connection
static boolean closeSQLStatement(java.sql.Statement statementObject)
          This method closes a JDBC statement
static java.sql.Connection createNewSQLConnection(JDBCDriverInfo driverInfo)
          This method will create a JDBC connection object from the JDBC driver information provided
static java.sql.Statement createNewSQLStatement(JDBCDriverInfo driverInfo)
          This method will create a JDBC statement object from the JDBC driver information provided
static java.sql.Statement createNewSQLStatementFromConnectionObject(java.sql.Connection connectionObject)
          This method will create a JDBC statement object from the JDBC connection object provided
static void createTable(java.sql.Statement stmt, java.lang.String tableName, java.lang.String[] columnNames, java.lang.String[] columnTypes)
          This method is used to create the specified table using the given attribute names and types.
static void deleteTable(java.sql.Statement stmt, java.lang.String tableName)
          This method is used to drop the featureSpecTable defined by this class from the database
static void flushTable(java.sql.Statement stmt, java.lang.String tableName)
          This method is used to empty the extraDataTable in the database defined by this class
static java.util.ArrayList readAllRowsOfQuery(java.sql.Statement stmt, java.lang.String query, java.lang.reflect.Method[] getMethods)
           
static java.util.ArrayList readAllRowsOfTable(java.sql.Statement stmt, java.lang.String tableName, java.lang.reflect.Method[] getMethods)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESULTSET_DOT_GETINT

public static final java.lang.reflect.Method RESULTSET_DOT_GETINT

RESULTSET_DOT_GETSTRING

public static final java.lang.reflect.Method RESULTSET_DOT_GETSTRING
Constructor Detail

DBTools

public DBTools()
Method Detail

createNewSQLConnection

public static java.sql.Connection createNewSQLConnection(JDBCDriverInfo driverInfo)
This method will create a JDBC connection object from the JDBC driver information provided

Parameters:
driverInfo - a JDBCDriverInfo
Returns:
a Connection

createNewSQLStatement

public static java.sql.Statement createNewSQLStatement(JDBCDriverInfo driverInfo)
This method will create a JDBC statement object from the JDBC driver information provided

Parameters:
driverInfo - a JDBCDriverInfo
Returns:
a Statement

createNewSQLStatementFromConnectionObject

public static java.sql.Statement createNewSQLStatementFromConnectionObject(java.sql.Connection connectionObject)
This method will create a JDBC statement object from the JDBC connection object provided

Parameters:
connectionObject - a Connection
Returns:
a Statement

readAllRowsOfTable

public static java.util.ArrayList readAllRowsOfTable(java.sql.Statement stmt,
                                                     java.lang.String tableName,
                                                     java.lang.reflect.Method[] getMethods)
Parameters:
stmt - The Statement object on which the query will be run.
tableName - The name of the table to read.
numCols - The number of columns in the table.
getMethods - An array of Method objects, where getMethods[i] is the ResultSet method to use to get the value from column i (0-based).
Returns:
ArrayList of Object[numCols], result.get(r)[c] is the rth row, cth column (0-based).

readAllRowsOfQuery

public static java.util.ArrayList readAllRowsOfQuery(java.sql.Statement stmt,
                                                     java.lang.String query,
                                                     java.lang.reflect.Method[] getMethods)

createTable

public static void createTable(java.sql.Statement stmt,
                               java.lang.String tableName,
                               java.lang.String[] columnNames,
                               java.lang.String[] columnTypes)
This method is used to create the specified table using the given attribute names and types.

Parameters:
stmt - an opened Statement
tableName - the name of the table to create
columnNames - the name of the columns or attributes
columnTypes - types for each of the columns.

deleteTable

public static void deleteTable(java.sql.Statement stmt,
                               java.lang.String tableName)
This method is used to drop the featureSpecTable defined by this class from the database

Parameters:
stmt - an opened Statement
tableName - name of the table to remove/drop

flushTable

public static void flushTable(java.sql.Statement stmt,
                              java.lang.String tableName)
This method is used to empty the extraDataTable in the database defined by this class

Parameters:
stmt - an opened Statement
tableName - name of the table to be flushed

closeSQLStatement

public static boolean closeSQLStatement(java.sql.Statement statementObject)
This method closes a JDBC statement

Parameters:
statementObject - a Statement
Returns:
a boolean

closeSQLConnection

public static boolean closeSQLConnection(java.sql.Connection connectionObject)
This method closes a JDBC connection

Parameters:
connectionObject - a Connection
Returns:
a boolean

closeResultSet

public static boolean closeResultSet(java.sql.ResultSet resultSet)
This method closes a JDBC resultset

Parameters:
resultSet - a ResultSet
Returns:
a boolean

closeAll

public static boolean closeAll(java.sql.Connection connectionObject,
                               java.sql.Statement statementObject)
This method closes a conection and statement

Parameters:
connectionObject - a Connection
statementObject - a Statement
Returns:
a boolean

closeAll

public static boolean closeAll(java.sql.Statement statementObject)
This method closes a conection and statement

Parameters:
statementObject - a Statement
Returns:
a boolean