I have a Spring Boot project where I'm trying to connect to a local PostgreSQL database. The data source is being instantiated from DataSourceBuilder. For the purposes of this example, I have the database username, password, and database URL hard-coded (they will be passed in through properties files), and this is what the implementation looks like:
String url = "jdbc:postgresql://localhost:5433/<TABLENAME>";
String username = <USERNAME>;
String password = <PASSWORD>;
return DataSourceBuilder
.create()
.driverClassName("org.postgresql.Driver")
.url(url)
.username(username)
.password(password)
.build();
When I run the Spring Application main method, the following exception is thrown:
Caused by: org.postgresql.util.PSQLException:
The server requested password-based authentication, but no password was provided.
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:534)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:141)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
I tried changing the postgres user password a few times using sudo passwd postgres but that didn't seem to work. Any ideas?