Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle and JDBC
I have had similar problems: I believe you have a malformed URL, try the
following:
Insert an additional slash between the file: and C:. Remember that URL's comprise <protocol>://<domain>/<path>
Cheers, Paul
Sam wrote:
> 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")});
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 - 06:29:25 CST