#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15

    Exception in thread "main" java.lang.UnsatisfiedLinkError: ocijdbc9


    I am trying to run a shell script in Unix and I am getting the following error:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: ocijdbc9 (Not found i
    n java.library.path)
    at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:949)
    at java.lang.ClassLoader.loadLibraryWithClassLoader(ClassLoader.java:918
    )
    at java.lang.System.loadLibrary(System.java:451)
    at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:267)
    at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:365)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
    va:547)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:347)
    at java.sql.DriverManager.getConnection(DriverManager.java:562)
    at java.sql.DriverManager.getConnection(DriverManager.java:186)
    I have researched online and found out that it might be caused by my enviorment variables however I set the following variables and it still does not work:

    ORACLE_HOME=c:\oracle\ora91
    CLASSPATH=......%ORACLE_HOME%\jdbc\lib;
    PATH=......%ORACLE_HOME%\lib;
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,419
    Rep Power
    1716
    Wait - are you on Unix or Windows? You're trying to use a DOS syntax on Unix and it won't work. Do you really have a C: drive in Unix?

    If you really are on Unix you need to learn a bit about it. First things first - the directory separator should lean forward, not backward. Secondly, Unix environment variables are prefixed with the $ character, not surounded by the % character like in dos.

    But the real problem you have is that your Java program cannot load the Oracle shared library. Unlike Windows Unix does not find shared libraries based on the PATH environment variable. Rather it uses another one. The name depends on the Unix you're on. For example, under Solaris and Linux the environment variable LD_LIBRARY_PATH is used. 64 bit Solaris uses LD_LIBRARY_PATH_64. HP/UX uses something somewhat different (depending on if your in a 32 or 64 bit O/S) and so on.

    What Unix are you running? Assuming Solaris/Linux for a second you'll want to have something like:

    Code:
    export ORACLE_HOME=/where/ever/oracle/is/installed
    export CLASSPATH=$ORACLE_HOME/jdbc/lib
    export LD_LIBRARY_PATH=$ORACLE_HOME%/lib
    It is important to note that under Unix the CLASSPATH separator is the colon character - : - not the semicolon. Same with the other separators. So if you have multiple things on any of the above environment variables have them delimited with a colon.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15
    Im actually running it on an AIX operating system.

    Here are my export statements.
    export ORACLE_HOME=/users/oracle/product/9.2.0
    export LD_LIBRARY_PATH=$ORACLE_HOME%/lib
    export PATH=$PATH:$ORACLE_HOME/bin
    When I run the shell script it still does not pick up the new variables. Any ideas?
  6. #4
  7. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,419
    Rep Power
    1716
    AIX uses LIBPATH instead of LD_LIBRARY_PATH. And I'd guess that the trailing % sign was a typo?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15
    how about the PATH variable....whats the diff from PATH and CLASSPATH?

    Thanks
  10. #6
  11. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,419
    Rep Power
    1716
    CLASSPATH is a Java specific thing. It tells the Java virtual machine where to look for Java libraries. PATH is used by the shell to located executables.

    As a general statement I wouldn't use the CLASSPATH environment variable. You're much better off using the -classpath option to the Java command. I would personally have a shell script that does something like (obviously the path names may be different)

    Code:
    #!/bin/bash
    ...
    
    export JAVA_HOME=/usr/java
    export ORACLE_HOME=/users/oracle/product/9.2.0
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
    $JAVA_HOME/bin/java -classpath $ORACLE_HOME/jdbc/lib:/anything/else the.java.package.and.ClassName
    or something like this. The problem is that CLASSPATH is global - any Java program you run will pick this up. To minimize the possibility of any issues I don't like to set it.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15
    Ok but instead of LD_LIBRARY_PATH...you would want LIBPATH. Right?
  14. #8
  15. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,419
    Rep Power
    1716
    Originally Posted by scooterp83
    Ok but instead of LD_LIBRARY_PATH...you would want LIBPATH. Right?
    Duh - yeah - too many years on Solaris systems
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15
    I have made these changes however i can not test them yet because now the UNIX box is down...lovely...but technically these changes should fix the problem right? I only ask this because i was reading somewhere online that when you run a shell script it actually makes a child shell where it runs and therefore the env variables can only be seen in the child shell and not the parent. Therefore when the classpath looks for the oracle driver it looks in the parent shell and does not find it. Does this make any sense? Or was that person totally making this up? Thanks

    Sorry im a newbie with this stuff and i appreciate your help
  18. #10
  19. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,419
    Rep Power
    1716
    That is what the export command does - it exports it to other shells.

    But an important caveat - the syntax I gave is bash or korn shell (ksh). If you are using a different shell then the programming syntax is a bit different. For example, if you're using the "normal" borne shell (/bin/sh) then the syntax is:

    Code:
    JAVA_HOME=/usr/java
    export JAVA_HOME
    and so on. If you're trying to write a very portable shell script then you will want to use this syntax (something some Linux developers miss). If you don't care and just want it to run on your AIX machine then I'd use bash/ksh syntax like I showed before.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15
    Yea i am doing it that way. I am also defining variables in its own properties file and then sourcing that file. Im doing this so that all i have to change is the prop file inorder to change the variables.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    15
    Here is what i have:

    properties file
    Code:
    .
    .
    .
    ORACLE_HOME=/users/oracle/product/9.2.0
    LIBPATH=$LIBPATH:$ORACLE_HOME/lib
    PATH=$PATH:$ORACLE_HOME/bin
    CLASSPATH=$CLASSPATH:$ORACLE_HOME/lib:$ORACLE_HOME/bin
    .
    .
    .
    shell script
    Code:
    #!/usr/bin/ksh
    
    # Source the properties file
    . $PWD/ococ011d.prop;
    
    export PATH
    export LIBPATH
    export ORACLE_HOME
    .
    .
    .
    .
    ! ${JAVA_HOME}/bin/java -classpath $CLASSPATH $JAVA_ARGS $PROG_NAME
    Technically this should work...i think

IMN logo majestic logo threadwatch logo seochat tools logo