没有找到适合 jdbc:postgresql://localhost:51020/university 的驱动程序


import java.sql.*;
public class a2 {
public static void main(String[] args) {
try{
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/univ_db", "postgre", "astronaut.pd");
PreparedStatement pstmt = con.prepareStatement("select id from student");
ResultSet Rs = pstmt.executeQuery();
while(Rs.next()){
System.out.println(Rs.getInt(5));
}
}catch(Exception ex){
System.out.println(ex.getMessage());
}}}

我正在尝试将我的服务器与我的数据库连接起来,但我不知道我在这方面做错了什么。我试图在网上搜索它,但没有找到任何解决方案。

错误:

找不到适合 jdbc:postgresql://localhost:5432/univ_db 的驱动程序

若要解决此错误,您需要在使用DriverManager.getConnection()获取连接之前获取驱动程序类引用using Class.forName()

例:

Class.forName(“org.postgresql.Driver”);

重要提示:请记住将 postgree 驱动程序导入您的 Java 项目。

相关内容

最新更新