Вопрос

i am trying to make jdbc oci connection to oracle 11g that uses os authentication

i made a sample console application to test the connection on some client machine

i developed the application on machine that has jdk 6 and used in the project the jar ojdbc6.jar.

the code i am using to connect to database is as follows:

OracleDataSource ods = new OracleDataSource();
String tnsName="Prod";
ods.setURL("jdbc:oracle:oci:/@"+tnsName);
Connection conn = ods.getConnection();

i am trying to run this application from client machine that has the oracle11g installed, and the oracle home is set on path to be: C:\orant\jdk\bin

also the path: C:\orant\bin contains oci.dll and doesn't contain ocijdbc11.dll

the client has jre7 installed and doesn't have jdk.

when trying to run the above code on client machine that is os authenticated to oracle database i am getting following exception:

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)
        at oracle.jdbc.driver.T2CConnection$1.run(T2CConnection.java:3178)
        at java.security.AccessController.doPrivileged(Native Method)
        at oracle.jdbc.driver.T2CConnection.loadNativeLibrary(T2CConnection.java
:3174)
        at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:233)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
508)
        at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:133)
        at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtensio
n.java:53)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
        at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSou
rce.java:275)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java
:206)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java
:156)
        at auth.Main.main(Main.java:42)

please advise how can i fix this exception.

Это было полезно?

Решение 2

i was able to make successful os connection to oracle database with jdbc in this post:

How to connect to oracle database with os authentication?

Другие советы

If you use an OCI url("jdbc:oracle:oci:/@"+tnsName) then you need oracle client libraries on the classpath. So you need have oracle client on the machine.

But if you use a thin driver and specify the url as the following, you don't need the oracle client.

"jdbc:oracle:thin:@"+dbServer+":"+port+":"+SID; 

try set correct values in /usr/share/tomcat/conf/tomcat.conf for ld_path:

LD_LIBRARY_PATH="/usr/lib/oracle/11.2/client64/lib:/usr/lib64"

If u are using Eclipse with Jboss 6.1.0 disturbution .it will shown error Exception in thread "main" java.lang.UnsatisfiedLinkError: no ocijdbc11 in java. library.path Solution : copy ocijdbc11.dll from oracle\product\11.2.0\client_1\BIN and paste in to

D:\jboss-6.1.0.Final\bin\native

I think you are getting this problem because you are using JRE 1.6 or below version of Java with type-2 driver. Please replace your JRE 1.6 buildpath by JRE 1.7 or JRE 1.8. It will solve the problem.

Please follow the steps:

  1. Right Click on your project folder
  2. Click on Properties
  3. Click on java build path.
  4. Select "jre system library" which is jre 1.6 or below from libraries and remove it cause this is becoming the source of cause.
  5. Now click add library
  6. Click jre system library
  7. Click next
  8. Select execution environment as JavaSE-1.8(jre1.8.0_144) by clicking environment button and then press ok.
  9. Click installed jre button
  10. Select jre1.8 from it (if jre1.8 is not present the click on add button and add it).
  11. Click Finish.
  12. Click ok.
  13. valah! you will find your code running.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top