heroku app runs OK remotely, but fails locally with "Failed to get driver instance for jdbcUrl=jdbc:postgresql://username@localhost"
after an insane day of troubleshooting, i got it to work. as near as i can tell, the commands gradlew build
and heroku local web
are only happy if the database user has a password.
by default when you install postgres on ubuntu you end up with a postgres account with the same name as your linux account, and with no password.
in my original attempts described in my OP above, i had some problems with the formatting of the values for environment variables DATABASE_URL
and JDBC_DATABASE_URL
. once i fixed that, i started getting the error The server requested password-based authentication, but no password was provided
, which i fixed by setting a password.
here are the steps that i followed:
1) set a password in postgres:
$psql#alter user username with password 'password';#\q
2) set the environment variables:
$export DATABASE_URL=postgres://username:password@localhost:5432/username$export JDBC_DATABASE_URL=jdbc:postgresql://localhost:5432/username?user=username\&password=password
(i am specifying a database with the same name as my user name).(the second export
command contains the &
character, which i must escape with a backslash).
3) build the project:
$./gradlew clean build
(you probably don't usually need the clean
part, but at least once today i found the clean
part necessary to reset some state).
4) start heroku local:
$heroku local web
5) browse to the endpoint that triggers a call to the database:
http://localhost:5000/db
this now displays the hoped-for output:
Database OutputRead from DB: 2019-04-27 19:48:38.764037Read from DB: 2019-04-27 19:58:30.007374
whew!