I am in the process of learning Java and PostgreSQL. I am running Windows 10 with JRE 10, my IDE being Eclipse Oxygen 3a. I had written the following code:
import java.sql.Connection;
import java.sql.DriverManager;
public class PostgreSQLJDBC {
public static void main(String args[]) {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/testdb",
"postgres", "123");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
}
It successfully compiles. However, it gives me the following error
java.lang.ClassNotFoundException: org.postgresql.Driver
In following the advice given in Stack Overflow, I have downloaded postgresql-42.2.2.jar and placed within C:\Program Files\Java\jre-10.0.1
I then edited my system variables and added "C:\Program Files\Java\jre-10.0.1" into it. However I still get the same error. Please help
C:\Program Files\Java\jre-10.0.1, it also doesn't belong in thesrcfolder, don't put it there.