Heroku JDBC
This is a helper library for parsing DATABASE_URL
from the environment and turning it into a JDBC connection.
Usage
In your pom.xml
:
<dependency>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-jdbc</artifactId>
<version>${heroku-jdbc.version}</version>
</dependency>
For PostgreSQL (the default):
Connection conn = DatabaseUrl.extract().getConnection();
For other Database vendors:
Connection conn = DatabaseUrl.extract().getConnection("mysql://");
For Spring or Apache DBCP:
DatabaseUrl dbUrl = DatabaseUrl.extract();
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setUrl(dbUrl.jdbcUrl(););
basicDataSource.setUsername(dbUrl.username());
basicDataSource.setPassword(dbUrl.password());
License
MIT