ca.idms.jcf
Class JdbcTable

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by ca.idms.jcf.JdbcTable
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class JdbcTable
extends javax.swing.table.AbstractTableModel

Converts the JDBC interface to the TableModel interface. This class can be used to implement a simple SQL utility that will execute update and query statements. The JTable data itself is not directly updatable. This class should work with any JDBC driver that does not requite catalog qualifiers in tables names for the DatabaseMetaData queries.

Note: This source code and the classes compiled from it are provided only for demonstration purposes, and are not a supported part of the CA IDMS Server product.

This class was converted to use generic types for CA IDMS Server r17 and requires Java 1.5 or later.

Version:
1.5 07/09/08
Author:
Dave Ross
See Also:
Serialized Form

Field Summary
protected  java.sql.Connection conn
           
protected  java.sql.SQLException ex
           
protected  java.sql.ResultSetMetaData md
           
protected  java.sql.DatabaseMetaData meta
           
protected  java.lang.String[] names
          Column names.
protected  java.util.Vector<java.util.Vector<java.lang.Object>> rows
          Column values.
protected  java.sql.Statement stmt
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
JdbcTable(java.lang.String driver)
          Constructs an object to execute SQL statements.
 
Method Summary
 void close()
          Closes the SQL statement and connection.
 void connect(java.lang.String url, java.lang.String uid, java.lang.String pwd)
          Connects to the database.
protected  void error(java.lang.Exception e)
          Returns a message in the JTable.
protected  void error(java.sql.SQLException e)
          Returns SQL error messages in the JTable.
 void execute(java.lang.String sql)
          Excecutes an SQL statement.
protected  void finalize()
           
 void getBestRowIdentifier(java.lang.String sp, java.lang.String tab, boolean nullable)
          Issues a JDBC getBestRowIdentifier() request.
 java.lang.Class<?> getColumnClass(int col)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int col)
           
 void getColumns(java.lang.String sp, java.lang.String tp, java.lang.String cp)
          Issues a JDBC getColumns() request.
 int getColumnWidth(int col)
          Gets preferred column width.
 void getCrossReference(java.lang.String pk_sp, java.lang.String pk_tab, java.lang.String fk_sp, java.lang.String fk_tab)
          Issues a JDBC getCrossReference() request.
 void getExportedKeys(java.lang.String sp, java.lang.String tab)
          Issues a JDBC getExportedKeys() request.
 void getImportedKeys(java.lang.String sp, java.lang.String tab)
          Issues a JDBC getImportedKeys() request.
 void getIndexInfo(java.lang.String sp, java.lang.String tab, boolean unique)
          Issues a JDBC getIndexInfo() request.
 void getPrimaryKeys(java.lang.String sp, java.lang.String tab)
          Issues a JDBC getPrimaryKeys() request.
 void getProcedureColumns(java.lang.String sp, java.lang.String tp, java.lang.String cp)
          Issues a JDBC getProcedureColumns() request.
 void getProcedures(java.lang.String sp, java.lang.String tp)
          Issues a JDBC getProcedures() request.
 int getRowCount()
           
 void getSchemas()
          Issues a JDBC getSchemas() request.
 void getTables(java.lang.String sp, java.lang.String tp)
          Issues a JDBC getTables() request.
 java.lang.Object getValueAt(int r, int c)
           
protected  void reset()
          Resets references.
protected  void result(java.sql.ResultSet rs)
          Return the result set for an SQL query.
protected  void tableChanged()
          Notifies all listeners of changes.
protected  void trace(java.lang.String s)
          Writes a trace line preceded by object identification.
protected  void update()
          Returns the update count for an SQL statement.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rows

protected java.util.Vector<java.util.Vector<java.lang.Object>> rows
Column values.


names

protected java.lang.String[] names
Column names.


conn

protected java.sql.Connection conn

meta

protected java.sql.DatabaseMetaData meta

stmt

protected java.sql.Statement stmt

md

protected java.sql.ResultSetMetaData md

ex

protected java.sql.SQLException ex
Constructor Detail

JdbcTable

public JdbcTable(java.lang.String driver)
Constructs an object to execute SQL statements.

Parameters:
driver - the name of the JDBC driver.
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - if an error occurs

getColumnName

public java.lang.String getColumnName(int col)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

getColumnClass

public java.lang.Class<?> getColumnClass(int col)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAt

public java.lang.Object getValueAt(int r,
                                   int c)

connect

public void connect(java.lang.String url,
                    java.lang.String uid,
                    java.lang.String pwd)
Connects to the database.

Parameters:
url - identifies the database.
uid - user id.
pwd - password.

execute

public void execute(java.lang.String sql)
Excecutes an SQL statement.

The result of the execution, whether it is a result set, updated count, or chain of exceptions, is returned in the JTable.

Parameters:
sql - the SQL statement.

getSchemas

public void getSchemas()
Issues a JDBC getSchemas() request.


getTables

public void getTables(java.lang.String sp,
                      java.lang.String tp)
Issues a JDBC getTables() request.

Parameters:
sp - schema name pattern
tp - table name pattern

getColumns

public void getColumns(java.lang.String sp,
                       java.lang.String tp,
                       java.lang.String cp)
Issues a JDBC getColumns() request.

Parameters:
sp - schema name pattern
tp - table name pattern
cp - column name pattern

getProcedures

public void getProcedures(java.lang.String sp,
                          java.lang.String tp)
Issues a JDBC getProcedures() request.

Parameters:
sp - schema name pattern
tp - procedure name pattern

getProcedureColumns

public void getProcedureColumns(java.lang.String sp,
                                java.lang.String tp,
                                java.lang.String cp)
Issues a JDBC getProcedureColumns() request.

Parameters:
sp - schema name pattern
tp - procedure name pattern
cp - column name pattern

getPrimaryKeys

public void getPrimaryKeys(java.lang.String sp,
                           java.lang.String tab)
Issues a JDBC getPrimaryKeys() request.

Parameters:
sp - schema name
tab - table name

getExportedKeys

public void getExportedKeys(java.lang.String sp,
                            java.lang.String tab)
Issues a JDBC getExportedKeys() request.

Parameters:
sp - schema name
tab - table name

getImportedKeys

public void getImportedKeys(java.lang.String sp,
                            java.lang.String tab)
Issues a JDBC getImportedKeys() request.

Parameters:
sp - schema name
tab - table name

getCrossReference

public void getCrossReference(java.lang.String pk_sp,
                              java.lang.String pk_tab,
                              java.lang.String fk_sp,
                              java.lang.String fk_tab)
Issues a JDBC getCrossReference() request.

Parameters:
pk_sp - primary key schema name
pk_tab - primary key table name
fk_sp - foreign key schema name
fk_tab - foreign key table name

getBestRowIdentifier

public void getBestRowIdentifier(java.lang.String sp,
                                 java.lang.String tab,
                                 boolean nullable)
Issues a JDBC getBestRowIdentifier() request. Scope is always set to bestRowTemporary

Parameters:
sp - schema name
tab - table name
nullable - true if including columns that are nullable

getIndexInfo

public void getIndexInfo(java.lang.String sp,
                         java.lang.String tab,
                         boolean unique)
Issues a JDBC getIndexInfo() request. Approximate parameter is always false.

Parameters:
sp - schema name
tab - table name
unique - true if method to return only indices for unique values

result

protected void result(java.sql.ResultSet rs)
               throws java.sql.SQLException
Return the result set for an SQL query.

Sets up the JTable with the values from the result set and its meta data.

Throws:
java.sql.SQLException - if an error occurs

update

protected void update()
               throws java.sql.SQLException
Returns the update count for an SQL statement. Sets up the JTable with the number of rows processed. Also displays any warnings

Throws:
java.sql.SQLException - if an error occurs

error

protected void error(java.sql.SQLException e)
Returns SQL error messages in the JTable.

Parameters:
e - the SQLException.

error

protected void error(java.lang.Exception e)
Returns a message in the JTable.

Parameters:
e - the Exception.

close

public void close()
Closes the SQL statement and connection.


getColumnWidth

public int getColumnWidth(int col)
Gets preferred column width.


tableChanged

protected void tableChanged()
Notifies all listeners of changes.


trace

protected void trace(java.lang.String s)
Writes a trace line preceded by object identification.

Parameters:
s - String to write.

reset

protected void reset()
Resets references.



Copyright © 2009 CA, All rights reserved