} catch(SQLException sqle) { RaiseErrorMessage("getDBTables Error: " + sqle.getMessage()); } catch(Exception e) { RaiseErrorMessage("getDBTables Error: " + e.getMessage()); } return true; }---------------------------------------------- 关键用法如下: DatabaseMetaData dm = conn.getMetaData(); String[] objCategories = {"TABLE"}; ResultSet rs = dm.getTables(DBName,null,"%",objCategories); ______________________________________________ getTables public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException Gets a description of tables available in a catalog. Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME. Each table description has the following columns: TABLE_CAT String => table catalog (may be null) TABLE_SCHEM String => table schema (may be null) TABLE_NAME String => table name TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". REMARKS String => explanatory comment on the table Note: Some databases may not return information for all tables.Parameters:catalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteriaschemaPattern - a schema name pattern; "" retrieves those without a schematableNamePattern - a table name patterntypes - a list of table types to include; null returns all typesReturns:ResultSet - each row is a table descriptionThrows:SQLException - if a database access error occurs
// cat 就是Oracle的管理表。
to :bill_hongs(hongs) -----用String tablename=rsm.getTableName(1);
得到的该是指定的列的名字吧。?
下面是我写的一个程序中的用来获取 TablesName 的一个方法:
/**
* getDBTables()
* @param DataOutputStream outFile
* @return boolean
*/
public boolean getDBTables(String DBName)
{
Connection conn = getConnection();
if ( conn == null )
return false;
try
{
DatabaseMetaData dm = conn.getMetaData();
String[] objCategories = {"TABLE"};
ResultSet rs = dm.getTables(DBName,null,"%",objCategories); printHTML("<table cellSpacing='1' cellPadding='3' width='600' bgColor='white' border='1' bordercolor='#006699' style='border-collapse: collapse; border-style: solid; font-size:10.5pt' id='DB_" + DBName +"'>");
printHTML("<tr bgColor='#e6e6e6'><td colspan='3'><b>数据库 " + DBName + " 数据结构</b></td></tr>");
printHTML("<tr bgColor='#cce6ff'><td width='50'><b>用户表</b></td><td> </td><td align='right'>< ></td></tr>");
while(rs.next())
{
printHTML("\t<tr height='2'><td colspan='3'></td></tr>"); String dbObjectName = rs.getString(3);
String dbObjectType = rs.getString(4);
printHTML("\t<tr id='TBL_" + dbObjectName + "' bgColor='#e6e6e6'>");
printHTML("\t\t<td width='80'>");
printHTML("\t\t\t<b>表名</b>");
printHTML("\t\t</td>");
printHTML("\t\t<td>");
printHTML("\t\t\t<b>" + dbObjectName);
printHTML("\t\t</b></td>");
printHTML("\t\t<td align='right' width='80'><a href='javascript:showTable(\"" + dbObjectName + "\");'>收缩</a> <a href='javascript:hideTable(\"" + dbObjectName + "\");'>展开</a></td>");
printHTML("\t</tr>");
printHTML("\t<tr id='TBLC_" + dbObjectName + "' style='display:\"\"'>");
printHTML("\t\t<td colspan='3'>");
//Enum Columns in Table
getTableColumns(DBName,dbObjectName);
printHTML("\t\t</td>");
printHTML("\t</tr>");
}
printHTML("</table>"); rs.close();
conn.close();
}
catch(SQLException sqle)
{
RaiseErrorMessage("getDBTables Error: " + sqle.getMessage());
}
catch(Exception e)
{
RaiseErrorMessage("getDBTables Error: " + e.getMessage());
}
return true;
}----------------------------------------------
关键用法如下:
DatabaseMetaData dm = conn.getMetaData();
String[] objCategories = {"TABLE"};
ResultSet rs = dm.getTables(DBName,null,"%",objCategories);
______________________________________________
getTables public ResultSet getTables(String catalog,
String schemaPattern,
String tableNamePattern,
String[] types)
throws SQLException Gets a description of tables available in a catalog. Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME. Each table description has the following columns: TABLE_CAT String => table catalog (may be null) TABLE_SCHEM String => table schema (may be null) TABLE_NAME String => table name TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". REMARKS String => explanatory comment on the table Note: Some databases may not return information for all tables.Parameters:catalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteriaschemaPattern - a schema name pattern; "" retrieves those without a schematableNamePattern - a table name patterntypes - a list of table types to include; null returns all typesReturns:ResultSet - each row is a table descriptionThrows:SQLException - if a database access error occurs
DM 对象用来干这个。for SQLServer 功能强大到足以实现大部分企业管理器的功能。如果要脱离数据库依赖,最好使用JDBC本身的技术来解决,而不是某个数据库系统提供的存储过程。
呵呵,careless说得没错儿,如果是join查询或者是多次复合查询的结果,RS中如何知道是从哪个表打开的?
我回答的问题是:枚举某个数据库中的表名
同样可以用DatabaseMetaData枚举某个表的存储过程、视图、字段等等。