All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.sql.DatabaseTable

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

public class DatabaseTable
extends 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 Index

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

Method Index

 o columnAt(String)
Returns the column of data indicated by the columnLabel.
 o databaseDelete(String, Connection)
Deletes rows of this table from a table in a database.
 o databaseInsert(String, Connection)
Add rows of this table to a table in a database.
 o databaseInsertTest(String)
 o databaseUpdate(String, String, Connection)
Updates rows of this table from a table in a database.
 o databaseUpdate(String, Vector, Connection)
Updates rows of this table from a table in a database.
 o elementAt(int, String)
Return the element in a given row and column.
 o fromSQL(String, Connection)
Create a DatabaseTable object on the result of the sqlSelect query.
 o getColumnLabels()
Return all the column labels
 o getColumnType(String)
Set the type of the elements of a column
 o getRow(String, String, String, Connection)
Create a DatabaseTable object containing selected rows a table from a database.
 o getTable(String, Connection)
Create a DatabaseTable object containing a table from a database.
 o numberOfColumns()
Returns the number of columns of data in the table.
 o numberOfRows()
Returns the number of rows of data in the table.
 o setColumnType(int, String)
Set the type of the elements of a column
 o setElementAt(Object, int, String)
Return the element in a given row and column.
 o toLabeledTable()
Convert DatabaseTable to a LabeledTable.
 o toString()
 o trimAll()
Remove leading and trailing spaces from all data elements

Constructors

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

 o DatabaseTable
 public DatabaseTable(ResultSet dateBaseContents) throws SQLException

Methods

 o fromSQL
 public static DatabaseTable fromSQL(String sqlSelect,
                                     Connection toDataBase) throws 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: SQLException
thrown on any error connecting to database or satisfying the query
 o getTable
 public static DatabaseTable getTable(String tableName,
                                      Connection toDataBase) throws 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: SQLException
thrown on any error connecting to database or obtaining the table.
 o getRow
 public static DatabaseTable getRow(String tableName,
                                    String column,
                                    String columnValue,
                                    Connection toDataBase) throws 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: SQLException
thrown on any error connecting to database or obtaining the table.
 o toString
 public String toString()
Overrides:
toString in class Object
 o toLabeledTable
 public LabeledTable toLabeledTable()
Convert DatabaseTable to a LabeledTable. Row zero contains the column vectors.

 o setColumnType
 public void setColumnType(int type,
                           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
 o getColumnType
 public int getColumnType(String columnLabel)
Set the type of the elements of a column

 o elementAt
 public Object elementAt(int row,
                         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.
 o setElementAt
 public void setElementAt(Object element,
                          int row,
                          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
 o columnAt
 public Vector columnAt(String columnLabel)
Returns the column of data indicated by the columnLabel. Column label is not in the returned vector.

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

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

 o getColumnLabels
 public Enumeration getColumnLabels()
Return all the column labels

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

 o databaseInsert
 public int databaseInsert(String dbTableName,
                           Connection toDataBase) throws 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
 o databaseInsertTest
 public int databaseInsertTest(String dbTableName) throws SQLException
 o databaseDelete
 public int databaseDelete(String dbTableName,
                           Connection toDataBase) throws 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
 o databaseUpdate
 public int databaseUpdate(String dbTableName,
                           String key,
                           Connection toDataBase) throws 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.
 o databaseUpdate
 public int databaseUpdate(String dbTableName,
                           Vector keys,
                           Connection toDataBase) throws 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.

All Packages  Class Hierarchy  This Package  Previous  Next  Index