Hi,
My goal is to allow users of my program to use Oracle drivers without
modifying their classpath. I have a question on the difference of these two
methods. Why does the first method fail?
P.S. ojdbc14.jar is Oracle's JDBC driver for Java 1.4. It used to be
class12.zip.
First method
URLClassLoader classLoader = new URLClassLoader(new URL[]{new
URL("file://C:/ojdbc14.jar")});
classLoader.loadClass("oracle.jdbc.driver.OracleDriver");
setDBConnection(DriverManager.getConnection("jdbc:oracle:thin:@localhost:152
1:mud", "wizard", "samlai"));
// Fail... it throws SQLException, but not ClassNotFoundException, so
oracle.jdbc.driver.OracleDriver is obviously loaded.
Second method
Class.forName("oracle.jdbc.driver.OracleDriver");
setDBConnection(DriverManager.getConnection("jdbc:oracle:thin:@localhost:152
1:mud", "wizard", "samlai"));
//Succeed, if ojdbc14.jar is in my classpath.
Thanks a lot,
Sam Lai
Received on Tue Jan 21 2003 - 02:24:54 CST