[JAVA] java.library.path

    

    jdbc:oracle:oci:@ 
 Uses the thick JDBC client and connects to the default local database. 

    jdbc:oracle:oci:@<tnsname> 
 Uses the thick JDBC client and connects to the specified database.
 
    jdbc:oracle:thin:@ 
 Uses the thin JDBC client and connects to the default local database 

    jdbc:oracle:thin:@<host>: port:<sid> 
 Uses the thin JDBC client and connects to a database with     the specified sid on the specified host on the specified port 
    

Oralce8i使用oci连接串为:jdbc:oracle:oci8:@
Oralce9i使用oci连接串为:jdbc:oracle:oci:@

数据库连接thin修改为oci连接方式时:


    java -classpath "../lib/confTools.jar:../lib/sunjce_provider.jar:../lib/classes12.jar:../lib/cardAward.jar" com.asiainfo.channel.common.TestOCI
    


出现如下异常


    Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't find library ocijdbc9  (libocijdbc9.a or .so) in sun.boot.library.path or java.library.path
    sun.boot.library.path=/usr/java14/jre/bin
    java.library.path=/usr/java14/jre/bin:/usr/java14/jre/bin/classic:/usr/java14/jre/bin:/data/fanhuan/center/lib:/data/fanhuan/lib:/opt/BDP/lib:/oracle/app/oracle/product/9.2.0/lib:/oracle/app/oracle/product/9.2.0/rdbms/demo:.:/usr/local/lib:/usr/dt/lib:/test3data/aibin/tcl/lib:/usr/lib
            at java.lang.ClassLoader.loadLibrary(ClassLoader.java:2020)
            at java.lang.Runtime.loadLibrary0(Runtime.java:824)
            at java.lang.System.loadLibrary(System.java:908)
            at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:262)
            at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:346)
            at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
            at java.sql.DriverManager.getConnection(DriverManager.java:539)
            at java.sql.DriverManager.getConnection(DriverManager.java:189)
            at com.asiainfo.channel.common.TestOCI.main(Unknown Source)
    

    


在$ORACLE_HOME/lib32下找到libocijdbc9.so,将$ORACLE_HOME/lib32加入到path及CLASSPATH后仍然出错。

查看java帮助

    Usage: java [-options] class [args...]
           (to execute a class)
        or  java [-jar] [-options] jarfile [args...]
           (to execute a jar file)

    where options include:
        -cp -classpath <directories and zip/jar files separated by :>
                  set search path for application classes and resources
        -D<name>=<value>
                  set a system property
    ......
    



在启动时,增加-D参数,设置java.library.path属性,结果连接数据成功。


    java -Djava.library.path=/oracle/app/oracle/product/9.2.0/lib32 -classpath "../lib/confTools.jar:../lib/sunjce_provider.jar:../lib/classes12.jar:../lib/nls_charset12.jar:../lib/ojdbc14.jar:../lib/cardAward.jar" com.asiainfo.channel.common.TestOCI 
    

    

采用OCI方式连接数据库,实际上是使用了JNI(Java Native Interface ),设置java.library.path属性是为了告诉java在哪里找到native libraries。

转载于:https://www.cnblogs.com/vanuan/archive/2006/02/16/9576180.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值