Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

java - Heroku Postgres is not connecting

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...