无法使用 java 连接到 postgresql

Can't connect to postgresql with java

在这个简单的示例中,我无法连接到 postgresql table。我不知道出了什么问题。请帮忙。

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());
        }
    }
}

控制台returns

"No suitable driver found for jdbc:postgresql://127.0.0.1:5432/students"

下载 postgresql jdbc (https://jdbc.postgresql.org/) 并将其添加到您的类路径