Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

I am running the Eclipse on the Windows operating system.

I had downloaded JDBC4, added it to my build path using Project>Properties>add External JAR, browsed for the file, it worked (.classpath file shows the correct lib path).

The package shows in my Referenced Libraries folder, so I am continuing the tutorial.

import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;

    ....

    public void open ()
        {
    try {
        Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    try {
        conn = DriverManager.getConnection(url, username, password);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

I think it would be as simple as that but I get hit with this big long stack trace starting with 

java.lang.ClassNotFoundException: org.postgresql.Driver

I tried include org.postgresql.*; but that didn't help either. I had also tried the JDBC3 but no luck there either. 

I'm very new to the Android, Postgresql and Web development, so a simple answer would be appreciated.

1 Answer

0 votes
by (12.7k points)
edited by

You must add the PostgreSQL JDBC Driver in to your project as mentioned in the search.maven.org.

Gradle:

implementation 'org.postgresql:postgresql:42.2.10'

Maven:

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.2.10</version> 

</dependency> 

You could also be able to download the JAR and import to your project manually.

NOTE: Compile it as used in this answer given is deprecated. Replace with implementation as per 3

Interested in SQL ? Check out this SQL Certification by Intellipaat.

For more information visit :

Related questions

0 votes
1 answer
0 votes
1 answer
asked Apr 6, 2021 in Java by Jake (7k points)

Browse Categories

...