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.

Published
Categorized as Java

By Greg Luck

As Terracotta’s CTO, Greg (@gregrluck) is entrusted with understanding market and technology forces and the business drivers that impact Terracotta’s product innovation and customer success. He helps shape company and technology strategy and designs many of the features in Terracotta’s products. Greg came to Terracotta on the acquisition of the popular caching project Ehcache which he founded in 2003. Prior to joining Terracotta, Greg served as Chief Architect at Australian online travel giant Wotif.com. He also served as a lead consultant for ThoughtWorks on accounts in the United States and Australia, was CIO at Virgin Blue, Tempo Services, Stamford Hotels and Resorts and Australian Resorts and spent seven years as a Chartered Accountant in KPMG’s small business and insolvency divisions. He is a regular speaker at conferences and contributor of articles to the technical press.

1 comment

  1. 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.

Comments are closed.