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。