当前位置: 代码迷 >> J2EE >> JDBC,DatabaseMetaData获取外键有关问题
  详细解决方案

JDBC,DatabaseMetaData获取外键有关问题

热度:20   发布时间:2016-04-22 02:16:51.0
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
  相关解决方案