Java Reference
In-Depth Information
}
}
catch(SQLException e){
reportException(e);
}
return typeVector;
}
The method getTableTypes() returns a ResultSet containing a single String column per row,
identifying the table type. Typically, these types are as follows:
 
TABLE
 
VIEW
 
SYSTEM TABLE
Using this table-type information, you can get the actual table names using the getTables() method.
An example is shown in Listing 10-5 .
Listing 10-5: Retrieving tables
public Vector getTables(String[] types){
Vector tableVector = new Vector();
try{
Connection con = DriverManager.getConnection(url,userName,password);
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getTables(null,null,"%",types);
ResultSetMetaData md = rs.getMetaData();
int nColumns = md.getColumnCount();
while(rs.next()){
tableVector.addElement(rs.getString("TABLE_NAME"));
}
}
catch(SQLException e){
reportException(e);
}
return tableVector;
}
The code to get the table names is similar to that used to get the table types. The most significant
difference is in the argument list for the getTables() method. Since these types of arguments are
fairly common when using metadata methods, it is worth discussing them in some detail.
The getTables() method takes these four arguments:
getTables(String catalog,
String schemaPattern,
String tableNamePattern,
String[] types);
Here are explanations of each argument:
Search WWH ::




Custom Search