corsiKa corsiKa - 2 months ago 19
Java Question

No suitable driver for postgres, even though Class.forName works?

I'm attempting to use the following Driver to connect to my postgresql database:


I'm using the following code:

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(

       at java.sql.DriverManager.getConnection(

       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...


All credit to a_horse_with_no_name's comment, but this question needs an answer.

Either specify a database in connection string or add a trailing slash.

Bad url: