java.sql.ResultSetMetaData
java.sql.DatabaseMetaData好象都没有这些信息,最好贴sample source上来,多谢!

解决方案 »

  1.   

    当然有啊,DatabaseMetaData meta = ...;
    meta.getExportedKeys/getImportedKeys 得到外键和被引用的外键
    meta.getPrimaryKeys 得到主键
      

  2.   

    Listing All Table Names in a Database    try {
            // Gets the database metadata
            DatabaseMetaData dbmd = connection.getMetaData();
        
            // Specify the type of object; in this case we want tables
            String[] types = {"TABLE"};
            ResultSet resultSet = dbmd.getTables(null, null, "%", types);
        
            // Get the table names
            while (resultSet.next()) {
                // Get the table name
                String tableName = resultSet.getString(3);
        
                // Get the table's catalog and schema names (if any)
                String tableCatalog = resultSet.getString(1);
                String tableSchema = resultSet.getString(2);
            }
        } catch (SQLException e) {
        }
      

  3.   

    SELECT table_name
    FROM User_tables t
    WHERE NOT EXISTS
    (SELECT table_name
    FROM User_constraints c
    WHERE constraint_type = 'P'
    AND t.table_name=c.table_name)其它相关数据字典解释
    user_tables 表
    user_tab_columns 表的列
    user_constraints 约束
    user_cons_columns 约束与列的关系
    user_indexes 索引
    user_ind_columns 索引与列的关系
      

  4.   

    晕,楼主说的那个二个类就能实现楼主所需要的所有功能了。
    楼上的错了吧,SQL语句应该不是楼主要的
      

  5.   

    我想的是传一个tablename进去,告诉我外键有哪些,主键是什么,你这样做
    1 怎么拿constraints?
    2 遍历整个库?虽然是遍历的是表名,不是数据,但性能也太慢了吧,我的库几千张表啊----------------------------------------------------------------------
     
     回复人: masse(当午) ( ) 信誉:100  2005-12-16 10:11:00  得分: 0  
    Listing All Table Names in a Database    try {
            // Gets the database metadata
            DatabaseMetaData dbmd = connection.getMetaData();
        
            // Specify the type of object; in this case we want tables
            String[] types = {"TABLE"};
            ResultSet resultSet = dbmd.getTables(null, null, "%", types);
        
            // Get the table names
            while (resultSet.next()) {
                // Get the table name
                String tableName = resultSet.getString(3);
        
                // Get the table's catalog and schema names (if any)
                String tableCatalog = resultSet.getString(1);
                String tableSchema = resultSet.getString(2);
            }
        } catch (SQLException e) {
        }
      

  6.   

    String[] types = {"TABLE"};
            ResultSet resultSet = dbmd.getTables(null, null, "%"+tablename, types);
    按表名
      

  7.   

    怎么都不看我的回复呢dbMeta.getPrimaryKeys(conn.getCatalog(), "myschema", "tablename") ;就返回了主键信息dbMeta.getImportedKeys/getExportedKeys(conn.getCatalog(), "myschema", "tablename") ;就返回了外键信息