0

我们需要在 Eclipse 中从 SQL Server 2005 中获取表名而不是 referenced_object_id。它是这样做的,但没有得到表名:

   Statement smt = con.createStatement();
            smt.executeQuery("SELECT * from table_references");
            ResultSet rs = smt.getResultSet();

            while (rs.next()) { 
                String column1 = rs.getString("referenced_object_id");
                String column2 = rs.getString("name");
                String column3 = rs.getString("parent_column_id");
                String column4 = rs.getString("referenced_column_id");

                String sql = "SELECT name from sys.tables WHERE object_id='" + column1 + "'";

                System.out.println(column1 + " | " + column2 + " | " + column3 + " | " + column4);
4

1 回答 1

1

您需要从数据库中获取元数据才能获取表的名称。

DatabaseMetaData meta = conn.getMetaData();  
ResultSet rs = meta.getTables(null, null, "%", null);
while (rs.next()) {
  System.out.println(rs.getString(3));
}

看看这里 - http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getTables%28java.lang.String,%20java.lang.String,%20java。 lang.String,%20java.lang.String%5b%5d%29 - 它会帮助你。

于 2013-05-24T15:08:44.510 回答