Hey guys I have a heroku web app with a PostgreSQL database. As you can see in the picture the DATABASE_URL
is set:
But for some reason when I try access the environment variable to connect to the database I get a NullPointerException
because apparently the DATABASE_URL
does not exist:
private static Connection getConnection() throws URISyntaxException, SQLException {
URI dbUri = new URI(System.getenv("DATABASE_URL"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
return DriverManager.getConnection(dbUrl, username, password);
}
What's going on here? How can I fix it?