View Single Post
Old 02-23-2011, 02:52 PM   PM User | #1
Cyf3r
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Cyf3r is an unknown quantity at this point
.Jar not working after export in Eclipse

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();
		}
	}
}
Cyf3r is offline   Reply With Quote