I want to connect to two different Oracle databases (one 8.0.5.0.0 and one 12c) via JDBC. I do have both JDBC drivers that can individually and successfully connect to the corresponding DB via simple "hello world" applications. Below, I have put both of them together into one Java application, which unfortunately does not work anymore (with both drivers being loaded).
I have read this post: Handle multiple JDBC drivers from the SAME VENDOR . The option 1 mentioned there might be the way to go, but there seems to be one major problem:
It seems that OracleDataSource
does not yet exist in the old version 8 driver and only has been introduced at later versions (in the 12c version driver it exists).
Any hints, on how to connect to these two Oracle databases with one single Java application and two JDBC drivers?
import java.sql.*;
class db {
public static void main (String args []) throws SQLException {
// Oracle 8 connection
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection c1 = DriverManager.getConnection(
"jdbc:oracle:thin:@some-oracle-8-server:port:sid",
"my-user",
"my-password");
Statement s1 = c1.createStatement ();
ResultSet r1 = s1.executeQuery ("SELECT banner FROM V$VERSION WHERE banner LIKE 'Oracle%'");
while (r1.next ()) {
System.out.println(r1.getString (1));
}
c1.close();
// Oracle 12 connection
Connection c2 = DriverManager.getConnection(
"jdbc:oracle:thin:@some-oracle-12-server:port:sid",
"my-user",
"my-password");
Statement s2 = c2.createStatement ();
ResultSet r2 = s2.executeQuery ("SELECT banner FROM V$VERSION WHERE banner LIKE 'Oracle%'");
while (r2.next ()) {
System.out.println(r2.getString (1));
}
c2.close();
}
}
Thanks in adavnce!