Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java和heroku postgresql之间的连接_Java_Postgresql_Heroku_Jdbc - Fatal编程技术网

java和heroku postgresql之间的连接

java和heroku postgresql之间的连接,java,postgresql,heroku,jdbc,Java,Postgresql,Heroku,Jdbc,我在heroku中创建了一个应用程序来使用远程数据库(postgres)。我可以在intellij idea或datagrip中轻松选择、插入、删除、更新。但我想通过java代码建立连接: public class ConnectionDB { public static void main(String[] args) throws URISyntaxException, SQLException { String dbURL = System.getenv("j

我在heroku中创建了一个应用程序来使用远程数据库(postgres)。我可以在intellij idea或datagrip中轻松选择、插入、删除、更新。但我想通过java代码建立连接:

    public class ConnectionDB {
  public static void main(String[] args) throws URISyntaxException, SQLException {
    String dbURL = System.getenv("jdbc:postgresql://----,,,,?????");
    Connection conn = DriverManager.getConnection(dbURL);
  }
}
但当我运行上述代码时,我得到:

Exception in thread "main" java.sql.SQLException: The url cannot be null
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:660)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
    at connection.ConnectionDB.main(ConnectionDB.java:11)

我也尝试了DATABASE_URL,但输出与JDBC_DATABASE_URL相同。如何解决此问题?

用于定义dbURL的行正在尝试访问可能不存在的环境变量

请从行中删除“System.getenv”以定义dbURL,或定义环境变量“dbURL”,然后使用
System.getenv('dbURL')
访问它:

或者,定义环境变量“dbURL”,然后使用:

String dbURL = System.getenv('dbURL');
Connection conn = DriverManager.getConnection(dbURL);
String dbURL = System.getenv('dbURL');
Connection conn = DriverManager.getConnection(dbURL);