I'm attempting to use the following Driver to connect to my postgresql database:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1204-jdbc41</version>
</dependency>
I'm using the following code:
Class.forName("org.postgresql.Driver");
System.out.println("Driver version: " + org.postgresql.Driver.getVersion());
String jdbcUrl = "jdbc:postgresql://localhost:5432";
String user = "postgres";
String pass = "password"; // super secure
Connection c = DriverManager.getConnection(jdbcUrl, user, pass);
And I get the following output
Driver version: PostgreSQL 9.4 JDBC4.1 (build 1204)
java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at [ the line Connection c = DriverManager... ]
So how is it that this 9.4 driver is not suitable? I know I can log in via my psql command line, but I can't seem to get it to work through Java.
I've done apps like this many times, but can't seem to see what I'm missing here...
jdbc:postgresql://localhost:5432/dbname
. Do you have other JDBC drivers on the classpath? Some actually intercept the way the DriverManager searches for the correct driver. – a_horse_with_no_namejdbc:postgresql://localhost:5432/
(note the trailing/
), instead ofjdbc:postgresql://localhost:5432
? – Mark Rotteveel