Я могу соединиться с pgAdmin, но не с JDBC, что я делаю неправильно?
JDBC:
Подход #1
String url = "jdbc:postgresql://localhost:5432/microlms360";
Properties props = new Properties();
props.setProperty("user","microlms360app");
props.setProperty("password","p0stgr@s");
props.setProperty("ssl","true");
Connection conn = DriverManager.getConnection(url, props);
Подход # 2
String url = "jdbc:postgresql://localhost:5432/microlms360?user=microlms360app&password=p0stgr@s&ssl=false";
try (Connection conn = DriverManager.getConnection(url)) {
boolean res = conn.createStatement().execute("SELECT 1");
System.out.println(res);
}
Результат одинаков в обоих случаях (я пробовал localhost
и 127.0.0.1
в качестве имени хоста. Напрасно.)
Connected to the target VM, address: '127.0.0.1:8648', transport: 'socket'
Exception in thread "main" org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:280)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.connect(Driver.java:256)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at iex.Main.main(Main.java:16)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.postgresql.core.PGStream.<init>(PGStream.java:70)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
... 7 more
Disconnected from the target VM, address: '127.0.0.1:8648', transport: 'socket'
Согласно этому блогу postgresql.org Я использую последнюю версию драйвера
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
UPD: процесс postgress фактически прослушивает, так что "ничего не слушайте порт"это не так