]>
git.argeo.org Git - gpl/argeo-slc.git/blob - CheckPg.java
bc002a6a51f1ad4c5ce81b82ceb708e28be20ee2
1 package org
.argeo
.cms
.sql
.postgres
;
3 import java
.sql
.Connection
;
4 import java
.sql
.ResultSet
;
5 import java
.sql
.SQLException
;
6 import java
.sql
.Statement
;
7 import java
.util
.ArrayList
;
9 import java
.util
.Properties
;
11 import org
.postgresql
.Driver
;
13 /** Simple PostgreSQL check. */
14 public class CheckPg
{
16 public List
<String
> listTables() {
17 String osUser
= System
.getProperty("user.name");
19 String url
= "jdbc:postgresql://localhost/" + osUser
;
20 Properties props
= new Properties();
21 props
.setProperty("user", osUser
);
22 props
.setProperty("password", "changeit");
23 List
<String
> result
= new ArrayList
<>();
25 Driver driver
= new Driver();
26 try (Connection conn
= driver
.connect(url
, props
); Statement s
= conn
.createStatement();) {
27 s
.execute("SELECT * FROM pg_catalog.pg_tables");
28 ResultSet rs
= s
.getResultSet();
30 result
.add(rs
.getString("tablename"));
33 } catch (SQLException e
) {
34 throw new IllegalStateException(e
);
38 public static void main(String
[] args
) {
39 new CheckPg().listTables().forEach(System
.out
::println
);