This discussion is archived
8 Replies Latest reply: Jul 1, 2013 4:18 AM by 85b1d353-231e-487a-957d-be472492018f RSS

Connect to DB2 from inside Oracle

599114 Newbie
Currently Being Moderated
Hi.

I am trying to to connect to DB2 v9.0 database from Oracle 10g R2. I've got the jar files db2jcc.jar and db2jcc_license_cu.jar as IBM says we need.

I loaded this files with loadjava to scott/tiger almost without problems. Also I loaded slqj.zip file. I've got only 3 objects inavlid after loading.

The problem comes with my stored procedure in Java that I call from PLSQL.

In statement Class.forName ("com.ibm.db2.jcc.DB2Driver"); it gives me this error:

ava.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:165)
at com.ibm.db2.jcc.DB2Driver.class$(DB2Driver.java:48)
at com.ibm.db2.jcc.DB2Driver.<clinit>(DB2Driver.java:51)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:165)
at TestDB2.DepartmentDescription(TestDB2.java:26)
Caused by: java.lang.NullPointerException
at java.util.StringTokenizer.<init>(StringTokenizer.java:146)
at java.util.StringTokenizer.<init>(StringTokenizer.java:162)
at com.ibm.db2.jcc.c.o.i(o.java:347)
at com.ibm.db2.jcc.c.o.h(o.java:338)
at com.ibm.db2.jcc.c.o.<clinit>(o.java:322)
... 7 more

I tried putting into CLASSPATH the db2jcc.jar and db2jcc_license_cu.jar files, but with no results.

Somebody has done something similar. There is someting missing ?
  • 1. Re: Connect to DB2 from inside Oracle
    kmensah Newbie
    Currently Being Moderated
    Hi,

    Make sure the DB2 jars are pure Java and that these work with JD 1.4 (which is the release OracleJVM in 10gR2 is compatible with).
    Classpath won't help in any way for Java in the database.

    Kuassi
    http://db360.blogspot.com
  • 2. Re: Connect to DB2 from inside Oracle
    599114 Newbie
    Currently Being Moderated
    Thanks for the answer.

    The drivers I am using are pure Java and I think they work with JRE 1.4 but I can't be sure of that because I couldn't find information in IBM's web. But I am almost sure that it must be compatible with JRE 1.4

    The question is why the sentence Class.forName ("com.ibm.db2.jcc.DB2Driver") is failing. I agree with you that system's CLASSPATH doesn't have any relationship with that, but still I can't know what happens.

    Is there somebody who has used DB2 driver inside Oracle ?
  • 3. Re: Connect to DB2 from inside Oracle
    599114 Newbie
    Currently Being Moderated
    Well, I will reply my own post, that's nice.

    Finally I found the way, after many hours spent. I will post because I think it will save many hours to other people.

    So, I connected DB2 v9 and Oracle 10g, using a Java stored procedure called from a PL/SQL storec procedure. This is the way to get it:

    1) Get the right DB2 JDBC driver

    Initially I was trying to use the official IBM JDBC driver using file db2jcc.jar, but finally we realized that it needed a license to connect to iSeries. So we tried another possibility given by IBM also. IBM provides an OpenSource DB2 driver called JTOpen or jt400. The driver file used is jt400.jar. You can download it at sourceforge.net. The official Web is http://jt400.sourceforge.net/

    2) Once you have the driver you will need to load it into Oracle using loadjava. I used the next sentence.

    loadjava -r -f -o -v -genmissing -grant public -user sys/password@database jt400.jar

    It's important to use sys user to load the jar file. Another user will give you problems, as it happened to me.

    3) Create a public synonym to driver class from SYS:

    CREATE PUBLIC SYNONYM "com/ibm/as400/access/AS400JDBCDriver" FOR "com/ibm/as400/access/AS400JDBCDriver";

    This will give the possibility to see the driver from another schemas when you use the sentence Class.forName("com.ibm.as400.access.AS400JDBCDriver"); to load the driver.

    4) Now you can create a class that uses the DB2 driver and the Oracle driver. The rest is pure Java JDBC programming.

    For example:

    public class ConnectDB2
    {
    public static void TestConnect(String server)
    {
    Connection conDB2;
    Connection conOra;

    // Load the DB2 JT400 Driver for JDBC
    System.out.println("**** Loading com.ibm.as400.access.AS400JDBCDriver");
    Class.forName("com.ibm.as400.access.AS400JDBCDriver");
    System.out.println("**** Loaded com.ibm.as400.access.AS400JDBCDriver");

    // Create the connection to DB2
    System.out.println("**** Trying to connect to database on server " + server);
    conDB2 = DriverManager.getConnection ("jdbc:as400://" + server, "db2user", "db2password");
    System.out.println("**** Connected");
    System.out.println("**** Created a JDBC connection to " + server);

    // Load the Oracle Driver for JDBC
    System.out.println("**** Loading oracle.jdbc.driver.OracleDriver");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("**** Loaded oracle.jdbc.driver.OracleDriver");

    // Create the connection to Oracle

    Properties oraProperties = new Properties();

    oraProperties.setProperty("user", "oracleuser");
    oraProperties.setProperty("password", "db2password");

    String url = "jdbc:oracle:thin:@" + "(DESCRIPTION=(ADDRESS=(HOST=hostname)" +
    "(PROTOCOL=tcp)(PORT=portnumber))" +
    "(CONNECT_DATA=(SID=databasesid)))";

    System.out.println("**** Trying to connect to database " + url);
    conOra = DriverManager.getConnection (url, oraProperties);
    System.out.println("**** Connected");
    System.out.println("**** Created a JDBC connection to url");

    etc ........

    I expect this can help somebody.
  • 4. Re: Connect to DB2 from inside Oracle
    604791 Newbie
    Currently Being Moderated
    It helped me !!!!

    Thanks.
  • 5. Re: Connect to DB2 from inside Oracle
    43545 Newbie
    Currently Being Moderated
    works for SYS user. does not work for other's
    gives: "ORA-29532: com.ibm.as400.access.AS400JDBCConnection: Implementation class not found." exception

    jt400 v7, 10g, 11g

    Edited by: dumchikov on Jun 20, 2010 10:28 AM
  • 6. Re: Connect to DB2 from inside Oracle
    user8731077 Newbie
    Currently Being Moderated
    Hi dumchikov,

    Im still having problem executing the loadjava with the ff statement :

    loadjava -r -f -o -v -genmissing -grant public -user sys/password@database jt400.jar

    when using the sys/password@database as the -user, most of the classes encountered this error message:

    ORA-29534: referenced object <class name> could not be re
    solved...

    Im using Oracle Database 10g....

    Though if I used the apps/apps as the -user i did not encounter the above error message but I am encountering this "*ORA-29532: Java call terminated by uncaught Java exception: java.sql.SQLException: The application requester cannot establish the connection.*" ...

    Hope you can help me with this...

    Thanks a lot in advance!
    dolps
  • 7. Re: Connect to DB2 from inside Oracle
    MarceloF.Ochoa Oracle ACE
    Currently Being Moderated
    Hi Dolps:
    Some class could not be resolved and your application can run without any problem if do not depend on the failed classes.
    Your problem seem to be a security problem, remember that the security manager do not have access to open external connection by default.
    You can get a full error message at the .trc file if you need grants to open tcp/ip connections.
    Please check your .trc files immediately after your application test, into the file there will be a full explanation of which grant is missing to complete the operation.
    Best regards, Marcelo.
  • 8. Re: Connect to DB2 from inside Oracle
    85b1d353-231e-487a-957d-be472492018f Newbie
    Currently Being Moderated

    hi

    i use ConncetDB class in my project load java file create scheme but it gives a Error

    ORA-29532: Java call terminated by uncaught Java exception: java.sql.SQLException: The application requester cannot establish the connection. (Connection refused)

    When i try to call the procedure it occurs...please Help