I want to connect to a PostgreSQL database using the JDBC 4.1 driver. I declared the following dependency in the pom.xml
:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1101-jdbc41</version>
</dependency>
This puts postgresql-9.3-1101-jdbc41.jar
into my classpath. I have read that it not necessary anymore to load the driver using Class.forName()
if the driver is specified at META-INF/services/java.sql.Driver
. The driver-jar has this file but I still get the following error:
No suitable driver found for jdbc:postgresql://localhost:5432
I just make a call to in a test and then run the tests using mvn test
:
DriverManager.getConnection("jdbc:postgresql://localhost:5432");
Even if I call Class.forName()
before I get the error. How do I get the driver loaded properly?