I am developing a database application in the Heroku + Jetty stack. I use Heroku Postgres as a database. I have a utility DB class that connects to a database and returns a connection. However, I keep getting the following errors:
If I run the following code, I get a "No suitable driver for jdbc found: 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 the following code to download the driver
Class.forName("org.postgresql.Driver");
If I do this, I get a Null Exception Pointer after the line.
Help identify the error if someone had a similar problem before. Thanks in advance.
Regards, Vineet
source share