0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.