Change JDBC to jdbc, it's case-sensitive.
java - Unable to make JDBC Connection [jdbc:postgres://localhost:5432/hibernatedb] - Stack Overflow
Flyway says ` No database found to handle jdbc:postgresql://localhost:5432/postgres` when using java migrator in jar only
java - Trouble connecting to postgresql via JDBC - Stack Overflow
How to connect to Postgres on localhost with URL: "jdbc:postgresql://database:5432/db123" - Database Administrators Stack Exchange
Change JDBC to jdbc, it's case-sensitive.
I found myself coming back to this and I think it is worth dropping an answer so it can guide someone else.
- 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.
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=postgresEdit your
.pgpassfile: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.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 filelocalhost: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
Set Permisions
In ther terminal type
chmod 600 ~/.pgpassTest 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:

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.
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.
- List item
- Right click on your project
- Select Build Path
- Click on Configure Build Path
- Click on Libraries and select Add External JARs
- Select the jar file from the required folder
- Click and Apply and Ok
then, you need to prepare the following:
- The address of the PostgreSQL database server
- The database name
- 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:
- Go to..\postgresql\9.0\data and open the file postgresql.conf in text editor/notepad
- Search for port parameter .eg: port = 5433
- Edit this to your port number.
- 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.