i want to connect to a postgresql database using the jdbc4 driver, but would like to set the classpath during the running of the program. The purpose is to register the driver for database connectivity. The following code explains what i intend to do, but alas the code doesn't work ("Couldn't find driver!"). why can't i connect this way? could i follow another way across for achieving the same?
String originalclasspath = System.getProperty("java.class.path");
System.setProperty("java.class.path",originalclasspath + ";E:\\postgresql-9.0-802.jdbc4.jar");
System.out.println(System.getProperty("java.class.path"));
System.out.println("Checking if Driver is registered with DriverManager.");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe) {
System.out.println("Couldn't find the driver!");
cnfe.printStackTrace();
System.exit(1);
}
please reply thanks in advance