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
- Download the instance client and unzip it into a directory. Let’s assume that directory is /u01/instantclient.
- 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.
- 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.
- Add
-Djava.library.path=/u01/instantclient
to your Java launch command. This tells java to add the path to its native library search path.
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.
Other horrors are