我想关于OCI Instant Client的配置应该没有《Oracle Database JDBC Developer's Guide and Reference》中来的详细了吧?以前从网上搜索来的解决方案,原来都可以在这本书中找到,疑惑和不解顿时减去了许多。现将这节摘录如下,详见:http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/instclnt.htm#CIHFDFJC
OCI Instant Client
This section covers the following topics:
Overview of Instant Client
The Instant Client feature makes it extremely easy to deploy OCI, Oracle C++ Call Interface (OCCI), Open Database Connectivity (ODBC), and JDBC-OCI based customer applications, by eliminating the need for an Oracle home. The storage space requirement of a JDBC OCI application running in the Instant Client mode is significantly reduced compared to the same application running on a full client-side installation. The Instant Client shared libraries occupy only about one-fourth the disk space used by a full client installation.
Table 6-1 shows the Oracle client-side files required to deploy a JDBC OCI application. Library names of release 11.1 are used in the table. The number part of library names will change in future releases to agree with the release.
Table 6-1 OCI Instant Client Shared Libraries
Linux and UNIX Systems | Description for Linux and UNIX Systems | Microsoft Windows | Description for Microsoft Windows |
---|---|---|---|
|
Client Code Library |
|
Forwarding functions that applications link with |
|
OCI Instant Client Data Shared Library |
|
Data and code |
|
Security Library |
|
Security Library |
|
OCI Instant Client JDBC Library |
|
OCI Instant Client JDBC Library |
ALL JDBC Java Archive (JAR) files |
See Also: "Check the Environment Variables" |
All JDBC JAR files |
See Also: "Check the Environment Variables" |
JDBC OCI Instant Client Installation Process
The Instant Client libraries can be installed by choosing the Instant Client option from Oracle Universal Installer. The Instant Client libraries can also be downloaded from the Oracle Technology Network Web site. The installation process is as follows:
-
Download and install the Instant Client shared libraries and Oracle JDBC class libraries to a directory, such as
instantclient
. -
Set the library path environment variable to the directory from Step 1. For example, on UNIX systems, set the
LD_LIBRARY_PATH
environment variable toinstantclient
. On Microsoft Windows, set thePATH
environment variable to locate theinstantclient
directory. -
Add the full path names of the JDBC class libraries to the
CLASSPATH
environment variable.
After completing these steps you are ready to run the JDBC OCI application.
The JDBC OCI application operates in the Instant Client mode when the OCI and JDBC shared libraries are accessible through the library path environment variable. In the Instant Client mode, there is no dependency on the ORACLE_HOME
and none of the other code and data files provided in ORACLE_HOME
is needed by JDBC OCI, except for the tnsnames.ora
file.
Instant Client can be also installed from Oracle Universal Installer by selecting the Instant Client option. The Instant Client files should always be installed in an empty directory. As with the OTN installation, you must set theLD_LIBRARY_PATH
environment variable to the Instant Client directory to operate in the Instant Client mode.
If you have done a complete client installation by choosing the Admin
option, then the Instant Client shared libraries are also installed. The location of the Instant Client shared libraries and JDBC class libraries in a full client installation is:
On Linux or UNIX systems:
-
libociei.so
library is in$ORACLE_HOME/instantclient
-
libclnstsh.so.11.1
,libocijdbc11.so
, andlibnnz11.so
are in$ORACLE_HOME/lib
-
The JDBC class libraries are in
$ORACLE_HOME/jdbc/lib
On Microsoft Windows:
-
oraociei11.dll
library is inORACLE_HOME\instantclient
-
oci.dll
,ocijdbc11.dll
, andorannzsbb11.dll
are inORACLE_HOME\bin
-
The JDBC class libraries are in
ORACLE_HOME\jdbc\lib
By copying these files to a different directory, setting the library path to locate this directory, and adding the path names of the JDBC class libraries to the CLASSPATH
environment variable, you can enable running the JDBC OCI application in the Instant Client mode.
Note:
-
To provide Native XA functionality, you must copy the JDBC XA class library. On UNIX, this library,
libheteroxa11.so
, is located inORACLE_HOME
/jdbc/lib
. On Windows, this library,heteroxa11.dll
, is located inORACLE_HOME
\bin
. -
All the libraries must be copied from the same
ORACLE_HOME
and must be placed in the same directory. -
On hybrid platforms, such as Sparc64, if the JDBC OCI driver needs to be operated in the Instant Client mode, then you must copy the
libociei.so
library from theORACLE_HOME
/instantclient32
directory. You must copy all other Sparc64 libraries needed for the JDBC OCI Instant Client from theORACLE_HOME
/lib32
directory. -
Only one set of Oracle libraries should be specified in the library path environment variable. That is, if you have multiple directories containing Instant Client libraries, then only one such directory should be specified in the library path environment variable.
-
If you have an Oracle home on your computer, then you should not have the
ORACLE_HOME
/lib
and Instant Client directories in the library path environment variable simultaneously, regardless of the order in which they appear in the variable. That is, only one ofORACLE_HOME
/lib
directory (for non-Instant Client operation) or Instant Client directory (for Instant Client operation) should be specified in the library path environment variable. -
Oracle recommends that you download Instant Client from Oracle Technology Network (OTN)
http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html
Usage of Instant Client
Instant Client is a deployment feature and should be used for running production applications. For development, a full installation is necessary to access demonstration programs and so on. In general, all JDBC OCI functionality is available to an application being run in the Instant Client mode, except that the Instant Client mode is for client-side operation only. Therefore, server-side external procedures cannot operate in the Instant Client mode.
Database Connection Names for OCI Instant Client
All Oracle Net naming methods that do not require the ORACLE_HOME
or TNS_ADMIN
environment variables to locate configuration files, such as tnsnames.ora
or sqlnet.ora
, work in the Instant Client mode. In particular, the connection string can be specified in the following formats:
-
A Thin-style connection string of the form:
host:port:service_name
For example:
url="jdbc:oracle:oci:@//example.com:5521:bjava21"
-
A SQL connection URL string of the form:
//host:[port][/service name]
For example:
url="jdbc:oracle:oci:@//example.com:5521/bjava21
-
As an Oracle Net keyword-value pair. For example:
url="jdbc:oracle:oci:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=dlsun242) (PORT=5521)) (CONNECT_DATA=(SERVICE_NAME=bjava21)))"
Naming methods that require TNS_ADMIN
to locate configuration files continue to work if the TNS_ADMIN
environment variable is set.
See Also:
Oracle Database Net Services Administrator's Guide for more information about connection formatsIf the TNS_ADMIN
environment variable is not set and TNSNAMES
entries, such as inst1
, are used, then the ORACLE_HOME
environment variable must be set and the configuration files are expected to be in the $ORACLE_HOME/network/admin
directory.
Note:
In this case, theORACLE_HOME
environment variable is used only for locating Oracle Net configuration files. No other component of Client Code Library uses the value of theORACLE_HOME
environment variable.The empty connection string is not supported. However, an alternate way to use the empty connection string is to set the TWO_TASK
environment variable on UNIX systems, or the LOCAL
variable on Microsoft Windows, to either atnsnames.ora
entry or an Oracle Net keyword-value pair. If TWO_TASK
or LOCAL
is set to a tnsnames.ora
entry, then thetnsnames.ora
file must be loaded by the TNS_ADMIN
or ORACLE_HOME
setting.
Consider that the listener.ora
file on the database server contains the following information:
LISTENER = (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=server6)(PORT=1573))) SID_LIST_LISTENER = (SID_LIST= (SID_DESC=(SID_NAME=rdbms3) (GLOBAL_DBNAME=rdbms3.server6.us.alchemy.com) (ORACLE_HOME=/home/dba/rdbms3/oracle)))
You can connect to this server in one of the following ways:
url = "jdbc:oracle:oci:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=server6)(PORT=1573)) (CONNECT_DATA=(SERVICE_NAME=rdbms3.server6.us.alchemy.com)))"
or:
url = "jdbc:oracle:oci:@//server6:1573/rdbms3.server6.us.alchemy.com"
Alternatively, you can set the TWO_TASK
environment variable to any of the connection strings and connect to the database server without specifying the connection string along with the sqlplus
command. For example, set theTWO_TASK
environment in one of the following ways:
setenv TWO_TASK "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=server6)(PORT=1573)) (CONNECT_DATA=(SERVICE_NAME=rdbms3.server6.us.alchemy.com)))"
or:
setenv TWO_TASK //server6:1573/rdbms3.server6.us.alchemy.com
Now, you can connect to the database server using the following URL:
url = "jdbc:oracle:oci:@"
The connection string can also be stored in the tnsnames.ora
file. For example, consider that the tnsnames.ora
file contains the following:
conn_str = (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=server6)(PORT=1573)) (CONNECT_DATA=(SERVICE_NAME=rdbms3.server6.us.alchemy.com)))
If this tnsnames.ora
file is located in the /home/webuser/instantclient
directory, then you can set the TNS_ADMIN
environment variable (or LOCAL
on Microsoft Windows) as follows:
setenv TNS_ADMIN /home/webuser/instantclient
Now, you can connect as follows:
url = "jdbc:oracle:oci:@conn_str"
Note:
TheTNS_ADMIN
environment variable specifies the directory where the tnsnames.ora
file is located. However, TNS_ADMIN
does not specify the full path of the tnsnames.ora
file, instead it specifies the directory.If this tnsnames.ora
file is located in the /network/server6/home/dba/oracle/network/admin
directory in the Oracle home, then instead of using TNS_ADMIN
to locate the tnsnames.ora
file, you can set the ORACLE_HOME
environment variable as follows:
setenv ORACLE_HOME /network/server6/home/dba/oracle
Now, you can connect with either of the conn_str
connection strings, as specified previously.
If tnsnames.ora
can be located by TNS_ADMIN
or ORACLE_HOME
, then TWO_TASK
can be set to:
setenv TWO_TASK conn_str
You can then connect with the following URL:
url = "jdbc:oracle:oci:@"
Environment Variables for OCI Instant Client
The ORACLE_HOME
environment variable no longer determines the location of the Globalization Support files and error message files. An OCI-only application does not require the ORACLE_HOME
environment variable to be set. However, if the variable is set, then it does not have an impact on the operation of the OCI driver. OCI will always obtain its data from the Data Shared Library. If the Data Shared Library is not available, only then is the ORACLE_HOME
environment variable used and a full client installation is assumed. Even though the ORACLE_HOME
environment variable is not required to be set, if it is set, then it must be set to a valid operating system path name that identifies a directory.
Environment variables ORA_NLS10
and ORA_NLSPROFILES33
are ignored in the Instant Client mode.
In the Instant Client mode, if the ORA_TZFILE
variable is not set, then the smaller, default, timezone.dat
file from the Data Shared Library is used. If the larger timezlrg.dat
file is to be used from the Data Shared Library, then set the ORA_TZFILE
environment variable to the name of the file without any absolute or relative path names. That is:
On UNIX systems:
setenv ORA_TZFILE timezlrg.dat
On Microsoft Windows:
set ORA_TZFILE timezlrg.dat
If the driver is not operating in the Instant Client mode, then the ORA_TZFILE
variable, if set, names a complete path name, as it does in previous Oracle Database releases.
If TNSNAMES
entries are used, then, as mentioned earlier, the TNS_ADMIN
directory must contain the TNSNAMES
configuration files, and if TNS_ADMIN
is not set, then the ORACLE_HOME/network/admin
directory must contain Oracle Net Services configuration files.