MAHI
MAHI

Reputation: 10163

jdbc metadata getTables to list only table list

i am trying to list tables from a database, when i use the below syntax

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

this returns me all the tables, views, index, system_tables from the database.

but i need only list of tables from the public schema so i have given the below syntax,

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

which shows me the following error

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

just need to list the tables alone from public schema.

plz help with the syntax

Upvotes: 2

Views: 8331

Answers (2)

Jim Garrison
Jim Garrison

Reputation: 86754

The signature for getTables() expects an array as the fourth argument. Try

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

Upvotes: 6

Brian Agnew
Brian Agnew

Reputation: 272217

The Javadoc suggests your last parameter should be an array of strings.

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

Upvotes: 6

Related Questions