I have a working app on Heroku with which I can't manage to connect to the database allocated on Heroku
The method that gets the connection:
public static Connection connect() {
Connection conn = null;
try {
conn = DriverManager.getConnection(System.getenv("JDBC_DATABASE_URL"));
System.out.println("Connected to the PostgreSQL server successfully.");
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
I check it with this other method on my API Rest:
@Path("/db")
@GET
public Response dbWorks() {
Connection conn = DBManager.connect();
if(conn != null) {
return Response.status(200).entity(conn).build();
}
return Response.status(400).entity(conn).build();
}
I does not work even if I write myself jdbc:postgresql://host:port/databasename with all the data that Heroku gives me.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…