2012-12-06 21 views
2

我試圖從數據庫中列出的表,當我使用下面的語法JDBC元數據的getTables僅列出表列表

ResultSet rs = md.getTables(null, null, "%" ,null); 

這將返回我所有的表,視圖,索引,system_tables從數據庫中。

,但我只需要在公共模式的表列表,所以我給下面的語法,

ResultSet rs = md.getTables(null, "public", "%" ,"TABLE"); 

這說明我下面的錯誤

required: String,String,String,String[] 
found: <null>,String,String,String 
reason: actual argument String cannot be converted to String[] by method invocation conversion 

只需要單獨列出表來自公共架構。

與語法

+0

傳遞一個數組「TABLE」作爲最後一個參數。請參閱Brian Agnew的回答 –

回答

6

Javadoc表明plz幫助你的最後一個參數應該是一個字符串數組

public ResultSet getTables(String catalog, 
          String schemaPattern, 
          String tableNamePattern, 
          String[] types) 
        throws SQLException 
4

getTables()的簽名需要數組作爲第四個參數。嘗試

ResultSet rs = md.getTables(null, "public", "%" ,new String[] {"TABLE"}); 
+0

,謝謝你的回答。 – MAHI