No suitable driver found for jdbc postgreSQL eclipse

Problem: Suppose you are creating an application using Java and for the backend you are using PostgreSQL, sometimes we face the error as below.
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/postgres
    at java.sql.DriverManager.getConnection(DriverManager.java:700)
    at java.sql.DriverManager.getConnection(DriverManager.java:258)
    at MyClass.main(MyClass.java:28)
       
Answer: There may be many reasons to generates this error.
1- First, make sure you have installed the jdbc.
2- It may be incorrect classpath, please check classpath the Dependent Jars should not be included inside your own jar, they should be placed next to your own jar and then be specified in the Class-Path in the MANIFEST.MF.

Eg Your layout could be:

your.jar
postgresql-9.3-1101.jdbc3.jar


Then the MANIFEST.MF of your.jar should have an entry:

Class-Path: postgresql-9.3-1101.jdbc3.jar


Follow the link for more details: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

3- JDBC 3 driver: The driver you are using is a JDBC 3 driver. Driver auto-loading was only introduced with JDBC 4 (Java 6). JDBC 4 autoloading works by drivers declaring what their driver class(es) are, presumably a JDBC 3 driver does not have that file. Your code has the Class.forName... commented out and the driver won't be loaded.

If you are using Java 6 or higher, upgrade to the JDBC 4 (Java 6) or JDBC 4.1 (Java 7) driver.

For the same types of the issue, there are some useful links are given below.

No comments:

Post a Comment

PostgreSQL: DROP TABLE is not working

Problem: I want to drop my table, but I am not able to drop the table while I tried the query "DROP TABLE MyTable CASCADE;". ...