How to solve java.lang.UnsatisfiedLinkError: no ocijdbc11 in Java

"java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path" error comes when you try to connect to Oracle 11g database using OCI (thick) driver by using tns name, but the ocijdbc11.dll file is not available in PATH or java.library.path environment variable. ocijdbc11.dll is a native library and if you know Java searches native library in PATH or a location specified by java.library.path system property, if it doesn't find the dll, then it throws java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path error. This dll is usually found in C:\Programs\Oracle\ora11g\bin\ocijdbc11.dll, but it could vary depending upon your Oracle installation.

The first step to solving this error is a search for this dll in your machine, if you are using windows, just search in your C drive. If the dll is not there then you need to download that from Oracle's website. If it's already present then just add its location into PATH variable.

If you are explicitly providing java.library.path then also provide it there e.g.
-Djava.library.path=C:\Programs\Oracle\ora11g\bin\ocijdbc11.dll . By the way, if you truly want to learn Java database programming from scratch, I suggest you take a look at Practical database programming with Java book by Ying Bai. This book explains every important detail of Java database connectivity.

Solution of  java.lang.UnsatisfiedLinkError: no ocijdbc11 in Java Oracle

By the way, this is not the standard way to connect to Oracle database from Java. Oracle users mainly use OCI driver for OS authentication or if they don't know the IP address of the server and want to connect using TNSE, but if you are not concerned of that, you can always use Oracle JDBC thin driver to connect. For that, you just need to include ojdbc.jar in your classpath.

Just remember if you use an OCI URL e.g. "jdbc:oracle:oci:/@"+tnsName then you are using thick driver and you need oracle client libraries on the PATH, for that you need Oracle client to be installed on your machine, but if you use thin driver with following URL format "jdbc:oracle:thin:@"+dbServer+":"+port+":"+SID; you just need driver's JAR file and no native library will be required because its type 4 pure Java driver.

Error :

Exception in thread "main" java.lang.UnsatisfiedLinkError: no ocijdbc11 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)

Analysis :

If you look at the error you will find that Java is complaining that ocijdbc11 dll is not found in java.library.path. If you further look then you will say that Oracle Driver is using System.loadLibrary() method to load the native library, which explains why Java is searching for dll in java.library.path.

Btw, this is optional if you don't provide this system property Java will look on all folders included in PATH environment variable.


There are two ways to solve the problem, first check if ocijdbc11.dll is present in your machine or not. For that do a wide search on your C driver where programs are installed.

If you don't find this dll file then you need to install Oracle client to get this dll. If you install Oracle 11g in 64-bit Windows 7 machine then this native library can be found in C:\Programs\Oracle\ora11g\bin\ocijdbc11.dll folder. Now just add this folder to your PATH and run your program again, provided any other error you should be able to connect to Oracle server.

The second solution is to use Oracle JDBC thin driver to connect Oracle database. For this you need to change your JDBC URL format as "jdbc:oracle:thin:@"+dbServer+":"+port+":"+SID; and include ojdbc6.jar in to your CLASSPATH.

Always remember the difference between PATH and CLASSPATH, PATH is used to locate executable files, native library files but JAR is always loaded from the classpath. This is also the standard way to connect to Oracle 11g database.

You can also see Core Java Volume II - Advanced Features by Cay S. Horstmann to learn more about database programming in Java using JDBC. One of the complete book to learn Java.

java.lang.UnsatisfiedLinkError: no ocijdbc11 in JDBC Oracle

java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path in SQL Developer

After Toad, Oracle's SQL Developer is the next popular tool for connecting to Oracle database and this a Java client. That's why you need both thick and thin driver in your machine, which I guess also comes when you install SQL Developer. It uses the thick driver when using TNS name and thin driver when using the basic connection.

For the thick driver, you need ocijdbc11.dll in your PATH and for the thin driver, you need ojdbc6.jar or ojdbc6_g.jar, later one is a debug version. So if you get this error while using SQL Developer, follow the above step to sort it out.

If you are using Oracle 10g then you will likely to see java.lang.unsatisfiedlinkerror no ocijdbc10 in java.library.path, the solution is same find the dll and add into PATH. Also, ojdbc6.jar can be found in C:\Programs\Oracle\ora11g\jdbc\lib\ location, where ORACLE_HOME.

How to fix java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path

Since this is also a type of java.lang.unsatisfiedlinkerror, you can also see this tutorial to get a general idea about how to solve this error in Java. You will likely to see this type of error whenever your Java program will use native libraries, either internal or external to do stuff.

That's all about how to fix java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path error in Java. You get this error when you try to connect to an Oracle 11g database from Java program by using its TNS name and not the IP address. You can fix this error by adding ocijdbc11.dll in your PATH environment variable or into your java.library.path variable.

If that DLL is not available in your system then download and install Oracle client like SQL Developer, which contains both thick and thin JDBC driver to connect to Oracle database. 

If you get java.lang.unsatisfiedlinkerror no ocijdbc10 in java.library.path means you are connecting to Oracle 10g database but the solution is same with the only difference in Oracle version difference. Let us know if you face any issue while connecting to Oracle database from Java and I will try to help you here. 

Other common error which comes while connecting to database like Oracle, MySQL, SQL SERVER from Java program :
  • How to connect to MySQL database from Java Program [steps]
  • General Guide to solve java.lang.ClassNotFoundException in Java [guide]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
  • How to fix java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
  • How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java MySQL? [solution]


rstaad said...

Your instructions are very thorough but I'm still stuck. Would you mind helping? Thank you.

Javin Paul said...

Hello rstaad, Sure, can you explain the problem and what you have tried so far?

Post a Comment