« HOWTO: Java 5 on Mac OS X 10.4 Tiger | Main | Integrating with Oracle 11i: Figuring Out the APIs »

May 03, 2005

The Horror of Oracle's OCI driver

It has been about two years since I last used Oracle's OCI driver. I remember it was painful to get going. I wish I had maintained a blog then, because I would have written the steps down and avoided a few hours of pain today. Which is why I am going to document what needs to be done. Hopefully some other poor soul can avoid the experience.

Step by step

  1. Download the instance client and unzip it into a directory. Let's assume that directory is /u01/instantclient.
  2. Copy the exact ojdbc14.jar in /u01/instantclient to your project's lib directory. The exact jar, and not a similar one needs to be in your classpath when you execute your java code.
  3. In your profile, say .bash_profile, add
    export LD_LIBRARY_PATH=/u01/instantclient
    . This lets Oracle's shared objects know where to find its other shared objects.
  4. Add
    -Djava.library.path=/u01/instantclient
    to your Java launch command. This tells java to add the path to its native library search path.
  5. Gotchas

    Oracle is silent on two of the three requirements. They mention the LD_LIBRARY_PATH but not the other two.

    The error messages when something goes wrong are not very informative.

    Posted by gluck at May 3, 2005 09:08 AM

    Comments

    Other horrors are
    • Oracle will probably be installed so the 64-bit libraries come first on the LD_LIBRARY_PATH, but your app server or java may not be 64-bit, resulting in hard-to debug segfaults.
    • They may not play nice with connection pools. E.g. they may not be returned to the pool after being closed, so you quickly run out of connections.
    • Using native libraries just does not work well with the classloaders on some app-servers. E.g. the native library can only be loaded once, if you deploy some new code that will try to load the native library, you'll have to restart the app server first.

    Posted by: Guy Mac at May 12, 2005 06:34 AM