java – "Connection refused" error connecting to PostgreSQL

Question:

The error happens after typing login and password:

"Deuorg.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."

I'm making the connection this way and I need it to stay that way for now:

<%
String url = "jdbc:postgresql://postgres-postgresconection.jelastic/siscosi";
String usuario = "xxxx";
String senha = "xxxx";
try {
    Class.forName("org.postgresql.Driver");
    Connection conexao = DriverManager.getConnection(url, usuario, senha);

Answer:

By default when creating an environment in Jelastic with a database, that database can only be accessed by applications in the same environment or by the web page (such as phpPgAdmin ).

So, to access the database, you need to enable the Public IPv4 address option, and this will increase your monthly cost a little more. By doing so, you will be given an IP to access it remotely and then add the IP as hostname in the connection URL.

In short, you have to have a valid IP to remotely access your database and your connection URL will look like this:

"jdbc:postgresql://IPRecebido/siscosi"

More information can be found here: Jelastic – PostgreSQL Remote Access

Scroll to Top