实际上我已经用谷歌搜索了一下,我需要相应的 SELECT 命令来遵循 PostgreSQL shell 命令:
\dt schemaname.*
我设法使用以下代码获取所有数据库:
Statement statement = (Statement) connection.createStatement();
ResultSet rs = statement
.executeQuery("SELECT datname FROM pg_database");
while (rs.next()) {
System.out.println("DB Name : " + rs.getString(1));
//i need another while here to list tables
//inside the selected database
}
我尝试了以下声明,但没有运气:
statement.executeQuery("SELECT table_schema,table_name FROM "
+ rs.getString(1)
+ " ORDER BY table_schema,table_name");
这是我得到的错误:
org.postgresql.util.PSQLException: ERROR: relation "template1" does not exist
Position: 37
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at com.isiran.rayten.rg.db.bare.wrapper.PGWrap.main(PGWrap.java:64)