I created an app in heroku to use remote db (postgres). I can easily select, insert, delete, update in intellij idea or datagrip. But i wanna make a connection via java code:
public class ConnectionDB {
public static void main(String[] args) throws URISyntaxException, SQLException {
String dbURL = System.getenv("jdbc:postgresql://----,,,,?????");
Connection conn = DriverManager.getConnection(dbURL);
}
}
But when i run the above pieces of code, i get:
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)
i tried DATABASE_URL also, but the same output as JDBC_DATABASE_URL. How to solve the problem?