Create a Heroku Postgres Client in Java

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.

1private static Connection getConnection()
2    throw URISyntaxException, SQLException, ClassNotFoundException {
3    Class.forName("org.postgresql.Driver");
4    URI dbUri = new URI(System.getenv("DATABASE_URL"));
5
6    String username = dbUri.getUserInfo().split(":")[0]
7    String username = dbUri.getUserInfo().split(":")[1]
8    String dbUrl = "jdbc:postgresql:''" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath();
9
10    return DriverManager.getConnection(dbUrl, username, password);
11    }

Product Retirement Announcement

Salesforce Functions is no longer available for purchase or renewal. To preserve the capabilities that Salesforce Functions provided to your org, deploy an alternative solution before your existing order term ends. See Salesforce Functions Retirement for more information on migrating your functions. Contact your Salesforce Account Executive for more information on Heroku.