ResultSetMetaData getTableName返回空String

时间:2014-06-30 10:58:53

标签: java

我试图通过以下代码

从ResultSetMetaData获取TableName
        Class.forName("oracle.jdbc.driver.OracleDriver");
        String url = "jdbc:oracle:thin:@localhost:1521:orcl";
         conn = DriverManager.getConnection(url,"releaseUN", "releasepw");
        Statement stmt = conn.createStatement();
        String qry = "";
        qry = "  SELECT  *  FROM MyTable ";

        ResultSet rset = stmt.executeQuery(qry);
        ResultSetMetaData md = rset.getMetaData();
        int col = md.getColumnCount();

         for (int i = 1; i <= col; i++) {
            System.out.println("getTableName "+ md.getTableName(i));

         }

但它返回Empty String 我使用ojdbc14.jar通过jdbc连接

连接到Oracle数据库

实际上我想要给定查询中每个选定列的表名 谢谢高级

1 个答案:

答案 0 :(得分:0)

ResultSetMetaData的文档说如果不适用则返回空白。

String getTableName(int column)
                    throws SQLException 
Gets the designated column's table name.
 Parameters:column - the first column is 1, 
the second is 2, ... 
Returns:table name or "" if not applicable 
Throws: SQLException - if a database access error occurs