I connect to a PostgreSQL server with: jdbc:postgresql://127.0.0.1/mydb?currentSchema=app96
.
I need to list tables that are present and create those that are missing during the initialization of my server.
Here's my code:
final ResultSet rs2 =
conn.getMetaData().getTables(null, "", null, new String[] { "TABLE" });
while (rs2.next()) {
System.out
.println(rs2.getString("TABLE_SCHEM") + "." + rs2.getString("TABLE_NAME"));
}
It prints:
app96.t1
app96.t2
public.administration$account
public.appmodule$uploadedfile
public.audittrail$audittrailsuperclass
...
From javadoc of getTables
:
schemaPattern ... "" retrieves those without a schema
But it seems that getTables
treats empty string the same way as null. Is there a pure JDBC way to filter by current schema or do I have to implement DB-specific filters myself?