Java Reference
In-Depth Information
Vector tableTypes = dbUtils.getTableTypes();
for(int i=0;i<tableTypes.size();i++){
DefaultMutableTreeNode tableTypeNode =
new DefaultMutableTreeNode((String)tableTypes.elementAt(i));
treeRoot.add(tableTypeNode);
String[] type = new String[]{(String)tableTypes.elementAt(i)};
Vector tables = dbUtils.getTables(type);
for(int j=0;j<tables.size();j++){
DefaultMutableTreeNode tableNode =
new DefaultMutableTreeNode(tables.elementAt(j));
tableTypeNode.add(tableNode);
Vector columns = dbUtils.getColumns((String)tables.elementAt(j));
for(int k=0;k<columns.size();k++){
Hashtable columnData = (Hashtable)columns.elementAt(k);
DefaultMutableTreeNode columnNode =
new DefaultMutableTreeNode(columnData.get("COLUMN_NAME"));
columnNode.add(new DefaultMutableTreeNode("TYPE_NAME:
"+columnData.get("TYPE_NAME")));
columnNode.add(new DefaultMutableTreeNode("COLUMN_SIZE:
"+columnData.get("COLUMN_SIZE")));
columnNode.add(new DefaultMutableTreeNode("IS_NULLABLE:
"+columnData.get("IS_NULLABLE")));
tableNode.add(columnNode);
}
}
}
return new DefaultTreeModel(treeRoot);
}
}
Most of the work in Listing 10-7 is done in the createTreeModel() method. This method first calls
the getTableTypes() method shown in Listing 10-4 to get a vector of table-type names. These are
used to create DefaultMutableTreeNodes attached to the root node representing the selected database.
For each table type, a vector of table names of that type is returned by the getTables() method
shown in Listing 10-5 . These are used to create DefaultMutableTreeNodes that are attached to the
table-type nodes representing each of the tables.
Finally, for each table, a vector of Hashtables of column descriptors is obtained by calling the
getColumns() method shown in Listing 10-6 . This information is used to create the column node and
column-information child nodes shown in Figure 10-2 . Only a small amount of the available column
information is used in this display for reasons of clarity. Additional fields that the getColumns()
method makes available include those listed in Table 10-2 .
Table 10-2: Column Information Provided by getColumns()
Column Name
Type
Meaning
TABLE_CAT
String
table catalog (may be null)
Search WWH ::




Custom Search