I'm new to java and I'm trying to connect to a Postgresql database. When I run my program in Eclipse itself it works but when I export it (to build a .jar) I get an exception.
java.lang.ClassNotFoundException: org.postgresql.Driver
The .classpath is created by Eclipse and contains
<classpathentry kind="lib" path="C:/Server/develop/resources/postgresql-8.4-702.jdbc4.jar"/>
The path is correct, when I copy and past it in my file browser I get the file.
Code:
import java.sql.*;
public class Main {
public static void main(String[] args) {
String url = "jdbc:postgresql://localhost/WorldCraft?user=postgres&password=sloeber007";
try {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection conn = DriverManager.getConnection(url);
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}