Vineet
Vineet

Reputation: 111

Java on Heroku/Jetty

I am developing a DB based application on Heroku + Jetty stack. I am using Heroku Postgres as database. I have a DB utility class that connects to database and returns connection. However, I keep getting following errors:

If I run the following code, I get "No suitable driver found for jdbc:postgresql://ec2-54-243-131-210.compute-1.amazonaws.com/d4s7l8b2vf1o8c" error.

            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.getPath();
            System.err.println("***** dbUrl IS CREATED ******");
            con = DriverManager.getConnection(dbUrl, username, password);
            System.err.println("***** CONNECTION IS CREATED ******");

I came across some comments suggesting adding following code to load the driver

Class.forName("org.postgresql.Driver");

If I do this, I get a Null Pointer Exception after the line.

Please help in identifying the error if someone have had similar challenge earlier. Thanks in advance.

Regards, Vineet

Upvotes: 4

Views: 1071

Answers (1)

Vineet
Vineet

Reputation: 111

Thanks for following up but I just resolved the issue.

Had dependency missing from pom file.

<dependency> 
<groupId>postgresql</groupId> 
<artifactId>postgresql</artifactId> 
<version>9.0-801.jdbc4</version> 
</dependency> 

Thanks.

Upvotes: 2

Related Questions