How to load specified version of oracle.jdbc.OracleDriver?

Hi.

I've faced problem while working with application that accesses different versions of Oracle(10gR2 and old one 8.0.5).

I have 2 jdbc libraries: classes12.zip(Oracle 8.0.5) and ojdbc14.jar(Oracle 10g).

In both libraries there is class oracle.jdbc.OracleDriver.

Is there any way to load specific driver, by classLoader?

i guess i need 2 method like this:

...

public Connection getOra8Connection(String uri,String username, String passwd){

...

//ClassLoader loads Ora8 driver and Instantiate Connection obj

...

}

public Connection getOra10gConnection(String uri,String username, String passwd){

...

//ClassLoader loads Ora10 driver and Instantiate Connection obj

...

}

...

any suggestions?

[1044 byte] By [dfundaka] at [2007-11-27 11:09:30]
# 1

If the classes have identical fully-qualified names, then, yes, you'll need to use a classloader. a URLClassLoader constructed with a URL to the correct library ought to do the trick

georgemca at 2007-7-29 13:35:48 > top of Java-index,Core,Core APIs...
# 2

Hi georgemc.

I'm trying to load driver like this

try {

URL ora8libURL = new URL("file:///C:/oracle/product/10.2.0/clientDev/jdbc/lib/classes12.jar");

Class.forName("oracle.jdbc.OracleDriver", true, URLClassLoader.newInstance(new URL[]{ora8libURL}));

conn = DriverManager.getConnection("jdbc:oracle:thin:@//192.168.186.13:1521/rdb817","user","password");

}

catch(ClassNotFoundException ex) {ex.printStackTrace();}

catch(MalformedURLException ex) {ex.printStackTrace();}

catch (SQLException ex) {ex.printStackTrace();}

but i've got this error:

java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@//192.168.186.13:1521/rdb817

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

However, when i specify driver explicit i works fine.

Message was edited by:

dfundak

dfundaka at 2007-7-29 13:35:48 > top of Java-index,Core,Core APIs...