【发布时间】:2021-03-07 18:19:43
【问题描述】:
在这个简单的示例中,我无法连接到 postgresql 表。而且我不知道出了什么问题。请帮忙。
package postgresql.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class PostgresWithJDBCConnection {
public static void main(String[] args) {
// establishes database connection
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/students", "postgres", "postgres")) {
System.out.println("Connection established successfully");
} catch (SQLException e) {
System.out.print(e.getMessage());
}
}
}
控制台返回
“没有找到适合 jdbc:postgresql://127.0.0.1:5432/students 的驱动”
【问题讨论】:
-
您是否下载了 Postgres 的 JDBC 驱动程序?如果是这样,是哪一个,哪个版本?你把司机的 JAR 放在哪里了?您的部署方案是什么?桌面应用?网络应用?如果是 web 应用程序,什么 web 容器?你是从 IDE 运行的吗?由于缺乏调试细节而投票结束。
-
请说明您是如何运行程序的。该错误表明 PostgreSQL JDBC 驱动程序不在类路径中。
标签: java postgresql jdbc