For Java, access your Heroku PostgreSQL database and DATABASE_URL with environment variable org.postgresql using method System.getenv to create a Postgres client instance.
private static Connection getConnection()
throw URISyntaxException, SQLException, ClassNotFoundException {
Class.forName("org.postgresql.Driver");
URI dbUri = new URI(System.getenv("DATABASE_URL"));
String username = dbUri.getUserInfo().split(":")[0]
String username = dbUri.getUserInfo().split(":")[1]
String dbUrl = "jdbc:postgresql:''" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath();
return DriverManager.getConnection(dbUrl, username, password);
}