Java 没有适合postgres的驱动程序,即使Class.forName有效?
我正在尝试使用以下驱动程序连接到我的postgresql数据库:Java 没有适合postgres的驱动程序,即使Class.forName有效?,java,postgresql,jdbc,Java,Postgresql,Jdbc,我正在尝试使用以下驱动程序连接到我的postgresql数据库: <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.4-1204-jdbc41</version> </dependency> 我得到以下输出 驱动程序版本:PostgreSQL 9.4
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1204-jdbc41</version>
</dependency>
我得到以下输出
驱动程序版本:PostgreSQL 9.4 JDBC4.1(build 1204)
java.sql.SQLException:未找到适合jdbc的驱动程序:postgresql://localhost:5432
位于java.sql.DriverManager.getConnection(DriverManager.java:689)
位于java.sql.DriverManager.getConnection(DriverManager.java:247)
在[线路连接c=DriverManager…] 那么,为什么9.4驱动程序不合适呢?我知道我可以通过psql命令行登录,但我似乎无法通过Java让它工作
我已经做过很多次类似的应用程序,但似乎看不出我在这里遗漏了什么…所有这些都归功于一匹没有名字的马,但这个问题需要一个答案 在连接字符串中指定数据库或添加尾部斜杠 错误的url: jdbc:postgresql://localhost:5432 好: jdbc:postgresql://localhost:5432/ 或
jdbc:postgresql://localhost:5432/thebestdatabase尝试向url追加数据库名:
jdbc:postgresql://localhost:5432/dbname
。类路径上是否有其他JDBC驱动程序?有些人实际上拦截了DriverManager搜索正确驱动程序的方式。哇。。。我希望它只使用默认数据库。。。显然我必须直截了当。。。如果您想创建一个答案,我很乐意为您提供支持。好吧,根据手册,数据库名称是可选的:您有没有可能尝试使用Java 1.6运行您的应用程序?您能试试jdbc:p吗ostgresql://localhost:5432/
(注意后面的/
),而不是jdbc:postgresql://localhost:5432
?真是救命恩人
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);