Java Reference
In-Depth Information
 
Catalog — a pair of double quotes ("") retrieves tables without a catalog, and null retrieves all
tables.
 
SchemaPattern — a pair of double quotes ("") retrieves tables without a schema, and null
retrieves all tables.
 
TableNamePattern — This is a table-name pattern similar to the argument used with SQL
"LIKE". The"%" matches any substring of 0 or more characters, and "_" matches any one character.
 
Types — an array of table types to include; null returns all types.
The getTables() method returns a ResultSet containing descriptions of the tables available in a
catalog. The result set contains the columns shown in Table 10-1 .
Table 10-1: Columns Returned by getTables()
Column
Column Name
Type
Contents
1.
TABLE_CAT
String
table_catalog (may be null)
2.
TABLE_SCHEM
String
table_schema (may be null)
3.
TABLE_NAME
String
table_name
4.
TABLE_TYPE
String
table_type: "TABLE", "VIEW", "SYSTEM TABLE",
etc.
5.
REMARKS
String
remarks explanatory comment on the table
Note
Some databases may not return information for all tables.
The DatabaseMetaData object also provides a mechanism to retrieve detailed information about the
columns in a table through the use of the getColumns() method. Like the getTables() method, the
getColumns() method returns a ResultSet. The method's argument list is also similar in that it takes a
number of String patterns:
public ResultSet getColumns(String catalog,
String schemaPattern,
String tableNamePattern,
String columnNamePattern);
Here are explanations of each argument:
 
Catalog — A pair of double quoutes ("") retrieves tables without a catalog, and null retrieves all
tables.
 
SchemaPattern — The double quotes ("") retrieve tables without a schema, and null retrieves
all tables.
 
TableNamePattern — This is a table name pattern similar to the argument used with SQL
"LIKE". The "%" matches any substring of 0 or more characters; "_" matches any one character.
 
columnNamePattern — This is a column name pattern similar to the argument used with SQL
"LIKE". The "%" matches any substring of 0 or more characters; "_" matches any one character.
Using the table information that the code in Listing 10-5 returns, you can get column information using
the getColumns() method. An example is shown in Listing 10-6 .
Listing 10-6: Retrieving column data
public Vector getColumns(String tableName){
Vector columns = new Vector();
Hashtable columnData;
try{
Connection con = DriverManager.getConnection(url,userName,password);
Search WWH ::




Custom Search