sdsu.sql
Class DatabaseTable

java.lang.Object
  |
  +--sdsu.sql.DatabaseTable

public class DatabaseTable
extends java.lang.Object

A class defines an interface for transfering tables between Java and a database. This class is easy to misuse. You still should use SQL to have the database perform the query, don't just download all the tables and then perform queries.

Version:
0.5 12 July 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Constructor Summary
DatabaseTable(java.sql.ResultSet dateBaseContents)
           
DatabaseTable(Table data)
          Creates a DatabaseTable with rows equal to the table data.
 
Method Summary
 java.util.Vector columnAt(java.lang.String columnLabel)
          Returns the column of data indicated by the columnLabel.
 int databaseDelete(java.lang.String dbTableName, java.sql.Connection toDataBase)
          Deletes rows of this table from a table in a database.
 int databaseInsert(java.lang.String dbTableName, java.sql.Connection toDataBase)
          Add rows of this table to a table in a database.
 int databaseInsertTest(java.lang.String dbTableName)
           
 int databaseUpdate(java.lang.String dbTableName, java.lang.String key, java.sql.Connection toDataBase)
          Updates rows of this table from a table in a database.
 int databaseUpdate(java.lang.String dbTableName, java.util.Vector keys, java.sql.Connection toDataBase)
          Updates rows of this table from a table in a database.
 java.lang.Object elementAt(int row, java.lang.String columnLabel)
          Return the element in a given row and column.
static DatabaseTable fromSQL(java.lang.String sqlSelect, java.sql.Connection toDataBase)
          Create a DatabaseTable object on the result of the sqlSelect query.
 java.util.Enumeration getColumnLabels()
          Return all the column labels
 int getColumnType(java.lang.String columnLabel)
          Set the type of the elements of a column
static DatabaseTable getRow(java.lang.String tableName, java.lang.String column, java.lang.String columnValue, java.sql.Connection toDataBase)
          Create a DatabaseTable object containing selected rows a table from a database.
static DatabaseTable getTable(java.lang.String tableName, java.sql.Connection toDataBase)
          Create a DatabaseTable object containing a table from a database.
 int numberOfColumns()
          Returns the number of columns of data in the table.
 int numberOfRows()
          Returns the number of rows of data in the table.
 void setColumnType(int type, java.lang.String columnLabel)
          Set the type of the elements of a column
 void setElementAt(java.lang.Object element, int row, java.lang.String columnLabel)
          Return the element in a given row and column.
 LabeledTable toLabeledTable()
          Convert DatabaseTable to a LabeledTable.
 java.lang.String toString()
           
 void trimAll()
          Remove leading and trailing spaces from all data elements
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DatabaseTable

public DatabaseTable(Table data)
Creates a DatabaseTable with rows equal to the table data.

DatabaseTable

public DatabaseTable(java.sql.ResultSet dateBaseContents)
              throws java.sql.SQLException
Method Detail

fromSQL

public static DatabaseTable fromSQL(java.lang.String sqlSelect,
                                    java.sql.Connection toDataBase)
                             throws java.sql.SQLException
Create a DatabaseTable object on the result of the sqlSelect query.
Parameters:
sqlSelect - sql query used to select data.
toDatabase - connection to the database that evaluates the sql query.
Throws:
java.sql.SQLException - thrown on any error connecting to database or satisfying the query

getTable

public static DatabaseTable getTable(java.lang.String tableName,
                                     java.sql.Connection toDataBase)
                              throws java.sql.SQLException
Create a DatabaseTable object containing a table from a database.
Parameters:
tableName - the name of the table in the database
toDatabase - connection to the database which contains the table to be downloaded into DatabaseTable object.
Throws:
java.sql.SQLException - thrown on any error connecting to database or obtaining the table.

getRow

public static DatabaseTable getRow(java.lang.String tableName,
                                   java.lang.String column,
                                   java.lang.String columnValue,
                                   java.sql.Connection toDataBase)
                            throws java.sql.SQLException
Create a DatabaseTable object containing selected rows a table from a database.
Parameters:
tableName - the name of the table in the database.
column - a column label in the table.
columnValue - select all rows that have this value in the given column
toDatabase - connection to the database which contains the table to be downloaded into DatabaseTable object.
Throws:
java.sql.SQLException - thrown on any error connecting to database or obtaining the table.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toLabeledTable

public LabeledTable toLabeledTable()
Convert DatabaseTable to a LabeledTable. Row zero contains the column vectors.

setColumnType

public void setColumnType(int type,
                          java.lang.String columnLabel)
Set the type of the elements of a column
Parameters:
type - the type of the elements as defined in java.sql.Types.
columnLabel - indicates the column that we are setting the type

getColumnType

public int getColumnType(java.lang.String columnLabel)
Set the type of the elements of a column

elementAt

public java.lang.Object elementAt(int row,
                                  java.lang.String columnLabel)
Return the element in a given row and column. Rows start at one.
Parameters:
row - index of the row of the element
columnLabel - label of the column of the element. Labels are converted to lower case to void case problems.

setElementAt

public void setElementAt(java.lang.Object element,
                         int row,
                         java.lang.String columnLabel)
Return the element in a given row and column. Rows start at one.
Parameters:
row - index of the row of the element
columnLabel - label of the column of the element

columnAt

public java.util.Vector columnAt(java.lang.String columnLabel)
Returns the column of data indicated by the columnLabel. Column label is not in the returned vector.

numberOfRows

public int numberOfRows()
Returns the number of rows of data in the table.

numberOfColumns

public int numberOfColumns()
Returns the number of columns of data in the table.

getColumnLabels

public java.util.Enumeration getColumnLabels()
Return all the column labels

trimAll

public void trimAll()
Remove leading and trailing spaces from all data elements

databaseInsert

public int databaseInsert(java.lang.String dbTableName,
                          java.sql.Connection toDataBase)
                   throws java.sql.SQLException
Add rows of this table to a table in a database.
Parameters:
dbTableName - name of the table in the database which rows will be inserted
toDataBase - a connection to the database which contains the table dbTableName
Returns:
total number of rows that were added to database table
Throws:
java.sql.SQLException -  

databaseInsertTest

public int databaseInsertTest(java.lang.String dbTableName)
                       throws java.sql.SQLException

databaseDelete

public int databaseDelete(java.lang.String dbTableName,
                          java.sql.Connection toDataBase)
                   throws java.sql.SQLException
Deletes rows of this table from a table in a database. Rows in the database table with are identical to the rows in this table will be deleted.
Parameters:
dbTableName - name of the table in the database which rows will be deleted
toDataBase - a connection to the database which contains the table dbTableName
Throws:
java.sql.SQLException -  

databaseUpdate

public int databaseUpdate(java.lang.String dbTableName,
                          java.lang.String key,
                          java.sql.Connection toDataBase)
                   throws java.sql.SQLException
Updates rows of this table from a table in a database. Rows in the database table with are identical to the rows in this table will be deleted.
Parameters:
dbTableName - name of the table in the database which will be updated.
key - column label used to select which rows in the database table to update. Any row in the database table that has the same value in the column indicated by key as a row in this table will be updated.
toDataBase - a connection to the database which contains the table dbTableName.
Throws:
java.sql.SQLException -  

databaseUpdate

public int databaseUpdate(java.lang.String dbTableName,
                          java.util.Vector keys,
                          java.sql.Connection toDataBase)
                   throws java.sql.SQLException
Updates rows of this table from a table in a database. Rows in the database table with are identical to the rows in this table will be deleted.
Parameters:
dbTableName - name of the table in the database which will be updated.
keys - Vector of column labela used to select which rows in the database table to update. Any row in the database table that has the same value in the columns indicated by keys as a row in this table will be updated.
toDataBase - a connection to the database which contains the table dbTableName.
Throws:
java.sql.SQLException -