我如何找到要连接到Postgres的数据库URL?

时间:2018-07-20 21:38:45

标签: java database postgresql

我有这个代码。它不起作用,因为它说“找不到适用于...的驱动程序”,我需要找到数据库URL。我如何找到它?我需要更改什么才能使我的代码连接到数据库并开始工作?...

  import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.SQLException;

       /**
    *
    * @author postgresqltutorial.com
   */
     public class InsertApp{

private final String url = "jdbc:postgresql://host:5432/lejdiprifti";
private final String user = "postgres";
private final String password = "<add your password>";

/**
 * Connect to the PostgreSQL database
 *
 * @return a Connection object
 */
public Connection connect() {
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(url, user, password);
        System.out.println("Connected to the PostgreSQL server successfully.");
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }

    return conn;
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    InsertApp app = new InsertApp();
    app.connect();
}
 }

0 个答案:

没有答案