Selhar
Selhar

Reputation: 136

Eclipse and postgres JDBC connection

i'm making a java web project and using Postgres for the database, but i can't get it to work, i'm using the most recent versions of all software (eclipse, postgres, tomcat) and drivers (JDBC postgres connection driver).

Here is my connection string:

private Connection getConnection() throws ClassNotFoundException,
            SQLException {
        if (cx == null) {
            String url = "jdbc:postgresql://localhost:5432/gregory";
            String login = "postgres";
            String senha = "postgres";
        //  Class.forName("org.postgresql.Driver");
            cx = DriverManager.getConnection(url, login, senha);

        }
        return cx;

    }

Here is the error:

HTTP Status 500 - javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/gregory

When i uncomment the class.forname line, i get this error instead:

javax.servlet.ServletException: java.lang.ClassNotFoundException: org.postgresql.Driver

I've added the postgres driver to the WEB-INF/lib folder, the root folder, tomcat's lib folder and the folder where my database access class is, the outcome is the same. I also added it through eclipse, myProject -> properties -> libraries -> add external JARs and tried to use JDBC4 and 3, and i have no results yet. Getting rather desperate here, any help would be very welcome.

Upvotes: 0

Views: 1610

Answers (1)

Selhar
Selhar

Reputation: 136

Solved. I tried to go in the "Data source explorer" and add a connection through there, in there, i found out that eclipse is only accepting JDBC 8.1 ( i don't know why, though ). So i downloaded the 8.1 driver and added it in Tomcat's lib folder, now it works perfectly, hope this helps someone.

Upvotes: 1

Related Questions