🌐
PostgreSQL
jdbc.postgresql.org › documentation › use
Initializing the Driver | pgJDBC
Defaults to localhost . To specify an IPv6 address your must enclose the host parameter with square brackets, for example: jdbc:postgresql://[::1]:5740/accounting · port = The port number the server is listening on. Defaults to the PostgreSQL® standard port number (5432).
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 12851363006482-Can-t-connect-to-local-Postgres-localhost-5432
Can't connect to local Postgres (localhost:5432) – IDEs Support (IntelliJ Platform) | JetBrains
August 2, 2023 - In my terminal, I'm pinging localhost fine and I can successfully telnet to 5432. I can get to the local DB using Postico as well. To try to get at this problem, I'm trying to configure a database within IDEA. It's pretty elementary. The URL is jdbc:postgresql://localhost:5432/postgres and all the other settings match my successful Postico configuration.
Discussions

java - Unable to make JDBC Connection [jdbc:postgres://localhost:5432/hibernatedb] - Stack Overflow
I'm trying to make a software using a database, and after many tries i have followed a tutorial on youtube. I'm using java 8, PostgreSQL 9.4 and Hibernate 5.2.2 (plus JBoss Tools 4.4.1). I follow... More on stackoverflow.com
🌐 stackoverflow.com
May 23, 2017
Flyway says ` No database found to handle jdbc:postgresql://localhost:5432/postgres` when using java migrator in jar only
Flyway says No database found to handle jdbc:postgresql://localhost:5432/postgres when using java migrator in jar only#3889 More on github.com
🌐 github.com
5
May 6, 2024
java - Trouble connecting to postgresql via JDBC - Stack Overflow
This file is usually located in ... or C:\PostgreSQL\data\ on Windows or similar. In this file we will edit the "listen_address" and "port" parameters, so that they look like below: ... listen_addresses = '0.0.0.0' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5432 # (change ... More on stackoverflow.com
🌐 stackoverflow.com
How to connect to Postgres on localhost with URL: "jdbc:postgresql://database:5432/db123" - Database Administrators Stack Exchange
I am able to connect to a postgres 10 instance on my local Win10 machine with pgAdmin 4 and "localhost" as a hostname, but when I change the hostname to "database" I cannot connect. How to fix it? ... More on dba.stackexchange.com
🌐 dba.stackexchange.com
Top answer
1 of 2
1

Change JDBC to jdbc, it's case-sensitive.

2 of 2
0

I found myself coming back to this and I think it is worth dropping an answer so it can guide someone else.

  1. The first thing that smells right to the face, is the case sensitive JDBC. Other answers here already advised you change to lower case, so I'll leave it at that.

However, there are other reasons changing JDBC to jdbc may not actually solve this error for you, and it is because the psql credentials (such as the POSTGRES_USER, POSTGRES_DB and POSTGRES_PASSWORD) may be totally wrong, and it is exactly the reason I do not have a connection in my own case.

Therefore, solving this, my advice will be configuring your .pgpass file, which stores credentials for PostgresSQL connection so as to avoid Database error :No suitable driver found for jdbc:postgresql://localhost:5432/..... prompt. Let's get into it.

  1. Note the credentials you created for your database*:

    I have created a pseudo example below which we will follow.

    # Example
    
    POSTGRES_HOST=your_host
    POSTGRES_PORT=your_port
    POSTGRES_DB=your_database_name
    POSTGRES_USER=your_user
    POSTGRES_PASSWORD=your_password
    
    # So, I will fill these items above with a pseudo credential below.
    # These false credentials is what I will use to explain how to fix it.
    
    POSTGRES_HOST=postgres
    POSTGRES_PORT=5432
    POSTGRES_DB=capital_one
    POSTGRES_USER=postgres
    POSTGRES_PASSWORD=postgres
    
  2. Edit your .pgpass file:

    Open your Terminal and type nano ~/.pgpass.

    nano, vi, etc are text editors, I believe your system may have it. If you don't have it, get it installed and learn how to create a file and save it with these editors before you proceed. This will help you to edit or create the .pgpass file and you can drop in the necessary configuration.

  3. Add your Database Entries:

    Kindly add your entry into the file in this format localhost:5432:your_database_name:your_username:your_password. So, based on the false credentials I created in Item 1, you will have something like this in your .pgpass file

    localhost:5432:capital_one:postgres:postgres

    Once you are done putting in the right entry, kindly save your entry and exit. If you dont know how, refer to this https://askubuntu.com/a/477606

  4. Set Permisions

    In ther terminal type chmod 600 ~/.pgpass

  5. Test your connection

    In your terminal, type psql -h localhost -d your_database_name -U your_username.

    Don't forget to provide the credentials you use. For my false/pseudo credentials above, it will be psql -h localhost -d capital_one -U postgres, then press Enter.

Now, for some people using Intellj IDE, this could be easy as well to text your connection before you apply it. See the image below:

🌐
RazorSQL
razorsql.com › articles › postgresql_jdbc_connect.html
How to Connect to PostgreSQL via JDBC
Connect to a PostgreSQL database named sample running on the local machine: jdbc:postgresql://localhost:5432/sample
🌐
Neon
neon.com › postgresql › postgresql-jdbc › connecting-to-postgresql-database
PostgreSQL JDBC: Connecting To The PostgreSQL Database
May 14, 2024 - db.url=jdbc:postgresql://localhost:5432/sales db.username=Yourusername db.password=YourPassword · The config.properties include three connection parameters: db.url: The URL of the PostgreSQL database server. In this example, we connect to the sales database on the local PostgreSQL server with port 5432 (default port).
🌐
Beekeeper Studio
beekeeperstudio.io › home › tools › postgresql jdbc url builder
PostgreSQL JDBC URL Builder | Beekeeper Studio
No, each PostgreSQL JDBC URL connects to a single database. To connect to multiple databases, you need separate URLs and connections. The default port is 5432.
🌐
Pinggy
pinggy.io › know_your_port › localhost_5432
localhost:5432 - PostgreSQL Database Port Guide - Pinggy
January 30, 2025 - Localhost:5432 is the official default port for PostgreSQL, the world’s most advanced open-source relational database. “Localhost” refers to your own computer (typically mapped to IP address 127.0.0.1), and “5432” is the port number ...
Find elsewhere
🌐
GitHub
github.com › flyway › flyway › issues › 3889
Flyway says ` No database found to handle jdbc:postgresql://localhost:5432/postgres` when using java migrator in jar only · Issue #3889 · flyway/flyway
May 6, 2024 - Flyway says No database found to handle jdbc:postgresql://localhost:5432/postgres when using java migrator in jar only#3889
Author   flyway
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-jdbc-driver
PostgreSQL JDBC Driver - GeeksforGeeks
July 23, 2025 - Connect to PostgreSQL: Use DriverManager.getConnection() to establish a connection to your PostgreSQL database using the JDBC URL (jdbc:postgresql://localhost:5432/your_database) and credentials (your_username and your_password).
🌐
CodeJava
codejava.net › java-se › jdbc › connect-to-postgresql-database-server-via-jdbc
Java Connect to PostgreSQL database server with JDBC
September 23, 2020 - String dbURL = "jdbc:postgresql://localhost:5432/ProductDB"; Properties parameters = new Properties(); parameters.put("user", "root"); parameters.put("password", "secret"); Connection conn = DriverManager.getConnection(dbURL, parameters);
Top answer
1 of 3
1

I think you can check whether your port number is wrong(default port number is 5432 not 5357) or you can use netstat -ntlp to check what port is open on your computer.

2 of 3
1

Reasons

  • Driver is not available.
  • Nothing is listening on the Port you are
  • Postgresql isn't running.
  • Postgresql isn't listening for TCP/IP connections.
  • Postgresql is listening on a different port to the one you're connecting on.

When the Postgresql server daemon is not running in the server, it can trigger connection refused error. At the same time, several other reasons can also trigger this error.

When you are scanning ports 1 to 65535, this is expected to happen with most ports. It's a sign that you should move on to the next port.

Solution

Download Latest PostgreSQL JDBC Driver

To connect to the PostgreSQL database server from a Java program, you need to have PostgreSQL JDBC driver. You can download the latest version of the driver on the postgresql.org website via the download page. The downloaded file is a jar file. You should copy it to a specific folder e.g. C:\demo\libs so that you can remember its location and be able to add it to your Java application later.

Then , add the PostgreSQL JDBC driver jar file to the project.

To import jar file in your Eclipse IDE, follow the steps given below.

  1. List item
  2. Right click on your project
  3. Select Build Path
  4. Click on Configure Build Path
  5. Click on Libraries and select Add External JARs
  6. Select the jar file from the required folder
  7. Click and Apply and Ok

then, you need to prepare the following:

  1. The address of the PostgreSQL database server
  2. The database name
  3. The username and password of the account that you will use to connect to the database.

For this information, you can construct the PostgreSQL JDBC connection string by using the following format:

To make it easier, we can define the attributes of the App class for storing connection string, user, and password:

private final String url = "jdbc:postgresql://localhost:5432/databasename";
private final String user = "yourname";
private final String password = "yourpassword";

Code should look like this

MainClass.java

package com.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MainClass {

private final String url = "jdbc:postgresql://localhost:5432/databasename";
private final String user = "yourname";
private final String password = "yourpassword";

public Connection connect() {
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(url, user, password);
        System.out.println("Connected to the PostgreSQL server successfully.");
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }

    return conn;
}

public static void main(String[] args) {
    App app = new App();
    app.connect();
}

}

Run a port scan

make sure the port is opened. To show all connections

Open cmd and enter following command and hit enter

netstat -a

You will see all the active connections from different states as shown below.

You need to edit postgresql.conf (inside your data directory) to set the new port there, then restart the postgresql service using the Services control panel or (as an Administrator) the net service command.

Edit postgresql.conf

This file is usually located in /var/lib/pgsql/data/ on Linux or C:\PostgreSQL\data\ on Windows or similar. In this file we will edit the "listen_address" and "port" parameters, so that they look like below:

Connection Settings

listen_addresses = '0.0.0.0'        # what IP address(es) to listen on;
                    # comma-separated list of addresses;
                    # defaults to 'localhost'; use '*' for all
                    # (change requires restart)
port = 5432             # (change requires restart)

Steps:

  1. Go to..\postgresql\9.0\data and open the file postgresql.conf in text editor/notepad
  2. Search for port parameter .eg: port = 5433
  3. Edit this to your port number.
  4. Go to run type services.msc and restart postgresql service.

Restart PostgreSQL

After that we need to restart PostgreSQL to activate the changes.

On Windows you can use Control Panel -> Administrative Tools -> Services and find service named postgres then restart the PostgreSQL service by right click -> properties - >stop then start.

🌐
PostgreSQL
postgresql.org › docs › 6.4 › jdbc19100.htm
PostgreSQL: Documentation: 6.4: Connecting to the Database
January 1, 2012 - With Postgres, this takes one of the following forms: ... The hostname of the server. Defaults to "localhost". ... The port number the server is listening on. Defaults to the Postgres standard port number (5432).
🌐
Stack Exchange
dba.stackexchange.com › questions › 216789 › how-to-connect-to-postgres-on-localhost-with-url-jdbcpostgresql-database54
How to connect to Postgres on localhost with URL: "jdbc:postgresql://database:5432/db123" - Database Administrators Stack Exchange
I am able to connect to a postgres 10 instance on my local Win10 machine with pgAdmin 4 and "localhost" as a hostname, but when I change the hostname to "database" I cannot connect. How to fix it? I've added to C:\Windows\System32\drivers\etc\hosts ... No success. ... UPD: there is nothing useful in server logs %HOME%\PostgreSQL10\data\log\postgresql-2018-09-05_181552.log (should/can I enable some restrictive logging level?)
🌐
Workiva
support.workiva.com › hc › en-us › articles › 360045854772-Postgres-connector
Postgres コネクタ – サポートセンター
The JDBC connection's URL, such as jdbc:postgresql://localhost:5432/sample · To connect to an on-premise database, a GroundRunner for the connection · From Chain Builder, click Connections compare_arrows, and then Create at the top right. Under Connector Connection, select Postgres and the runner to use with the connection.
🌐
GitHub
github.com › quarkusio › quarkus › issues › 30701
Connecting to PostgreSQL DB is failing with native-image · Issue #30701 · quarkusio/quarkus
January 30, 2023 - quarkus: datasource: db-kind: ${CONFDB_DATABASE_KIND:postgresql} username: ${CONFDB_DATASOURCE_USERNAME:usernam} password: ${CONFDB_DATASOURCE_PASSWORD:password} jdbc: url: ${CONFDB_DATASOURCE_JDBC_URL:jdbc:postgresql://localhost:5432/my_database} max-size: ${CONFDB_CONNECTION_POOL_MAX_SIZE:2} min-size: ${CONFDB_CONNECTION_POOL_MIN_SIZE:2} Environment variables in the container: bash-4.4$ env | grep CONFDB CONFDB_DATASOURCE_JDBC_URL=jdbc:postgresql://localhost/test CONFDB_CONNECTION_POOL_MAX_SIZE=2 CONFDB_DATASOURCE_USERNAME=username CONFDB_CONNECTION_POOL_MIN_SIZE=2 CONFDB_DATASOURCE_PASSWORD=password CONFDB_DATABASE_KIND=postgresql ·
Author   quarkusio
🌐
Baeldung
baeldung.com › home › persistence › connect with postgresql database over ssl
Connect with PostgreSQL Database over SSL | Baeldung
July 22, 2024 - spring: application: name: postgresqlssltest datasource: url: jdbc:postgresql://localhost:5432/testdb?ssl=true&sslmode=verify-ca&sslrootcert=certs/root.crt&sslcert=certs/pg_client.crt&sslkey=certs/pg_client.pk8 username: postgres password: "password" driver-class-name: org.postgresql.Driver jpa: hibernate: ddl-auto: update database-platform: org.hibernate.dialect.PostgreSQLDialect ·
🌐
Confluent
forum.confluent.io › kafka connect
No suitbale Diver for JDBC-Connector PostgreSQL - Kafka Connect - Confluent Community
July 18, 2024 - Hi, I am new to Kafka and I am trying to get my JDBC-Connector started but I got the same error over and over: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/TEST_SM I already read …