A
A
alexeenko1012015-04-01 01:28:52
PostgreSQL
alexeenko101, 2015-04-01 01:28:52

How to connect to postgresql in java?

through pgAdmin it was possible to connect, and when trying to connect in java, an exception flies.

Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(
          "jdbc:postgresql://109.104.172.25:5432/postgres?user=pgsql&password=pwd");

exception:
org.postgresql.util.PSQLException: ?????: ? pg_hba.conf??? ??????, ????????????? ??????????? ??? ?????????? ? ?????????? "100.100.45.142"??? ???????????? "pgsql", ???? ?????? "postgres", SSL ????.
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:420)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:195
) .java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection.java:127)
at org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection.java:29)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.c3Abstraction.Jdb :
at org.postgresql.jdbc4.AbstractJdbc4Connection.(AbstractJdbc4Connection.java:41)
at org.postgresql.jdbc4.Jdbc4Connection.(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:414)
at org. postgresql.Driver.connect(Driver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:243)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexeenko101, 2015-04-02
@alexeenko101

the snag was in ssl.
fixed like this

String url = "jdbc:postgresql://HOST:5432/TABLE?"+
        "ssl=true&"+
        "sslfactory=org.postgresql.ssl.NonValidatingFactory";
      String user = "pgsql";
      String password = "PWD";
        
  Class dbDriver = Class.forName("org.postgresql.Driver");
      con = DriverManager.getConnection(url, user, password);

V
Vladimir Smirnov, 2015-04-01
@bobzer

Learn Google. Here is the answer in Russian: no pg_hba.conf entry for host

N
Nikita, 2015-04-01
@jkotkot

There are suspicions that the questions say about the prohibition of remote connections.
In general, it is best to pass the name and password parameters not in the url, but as method call parameters.
PS connect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question