【发布时间】:2014-06-26 20:05:05
【问题描述】:
我想使用 JDBC 4.1 驱动程序连接到 PostgreSQL 数据库。我在pom.xml 中声明了以下依赖项:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1101-jdbc41</version>
</dependency>
这会将postgresql-9.3-1101-jdbc41.jar 放入我的类路径中。我已经读过,如果驱动程序在META-INF/services/java.sql.Driver 中指定,则不再需要使用Class.forName() 加载驱动程序。 driver-jar 有这个文件,但我仍然收到以下错误:
No suitable driver found for jdbc:postgresql://localhost:5432
我只是在测试中调用,然后使用mvn test 运行测试:
DriverManager.getConnection("jdbc:postgresql://localhost:5432");
即使我在收到错误消息之前致电Class.forName()。如何正确加载驱动程序?
【问题讨论】:
标签: java postgresql maven jdbc