日期:2014-05-20  浏览次数:20724 次

JDBC,DatabaseMetaData获取外键问题

Java code

public static Set getForeignKeyColumns(Connection c, String catalog, String schema, String table) throws SQLException {      
                DatabaseMetaData dmd = c.getMetaData();      
                ResultSet rs = null;      
                HashSet columns = new HashSet();   
                try {      
                    rs = dmd.getImportedKeys(catalog, schema, table);      
                      
                    while (rs.next()) {      
                        columns.add(rs.getString(8));      
                   }      
                        
                }catch(Exception e){
                    e.printStackTrace();
                }
                finally {      
                    if (rs != null) rs.close();
                    return columns; 
                }      
            }      


获取主键是没问题的。。但外键就拿不到了。。 
那个获取外键的。。我怎么弄也是查不出来。。又不报错。。甚至连我表名打错也没报错~麻烦大家能不能帮我找下原因。。
还有String catalog, String schema。这两上参数是什么意思的??网上查了下后。。都还是看不懂。。。

------解决方案--------------------
http://baike.baidu.com/view/1374119.htm
http://dict.baidu.com/s?wd=catalog