Hi.baidu.comanboqingblogitem5a7b49f4e36fb57ddcc4744a.html recently learned to connect to the oracle database using the java language. Specifically, the two jdbc Connection Methods oci and thin are two sets of Java access to the Oracle database provided by Oracle. Thin is a thin client connection method.
Http://hi.baidu.com/anboqing/blog/item/5a7b49f4e36fb57ddcc4744a.html recently learned to use java to connect to the oracle database, specifically queries the jdbc Two Connection Methods oci and thin is Oracle provides two sets of Java access to the Oracle database. Thin is a thin client connection method.
Http://hi.baidu.com/anboqing/blog/item/5a7b49f4e36fb57ddcc4744a.html
I recently learned how to connect to the oracle database using the java language. I specifically checked two jdbc connection methods.
Oci and thin are two sets of Java access methods provided by Oracle to access the Oracle database.
Thin is a thin client connection method. In this connection mode, you do not need to install the oracle client. You only need to include the jdbc driver jar package in classpath. Thin is an ORACLE database access interface written purely in Java.
Oci is a fat client connection method, that is, to use this connection method, you need to install the oracle client. Oci is the abbreviation of Oracle Call Interface. It is an access Interface provided by ORACLE. It uses Java to Call the local Oracle client and then access the database. The advantage is that it is fast, however, you must install and configure the database.
The following points can be summarized from relevant materials:
1. in terms of usage, oci must install the oracle client on the client or connect to the database, but thin is not required. Therefore, thin is more convenient to use, which is also a common reason for thin.
2. in principle, thin implements tcp/ip c/s communication only in java. In oci mode, the client calls c library through native java method to access the server, this c library is the oci (oracle called interface). Therefore, this oci always needs to be installed with the oracle Client (from oracle10.1.0, the OCI Instant client is provided separately, and the complete Client installation is not required)
3. They are different driver categories, oci is a Class-2 driver, and thin is a Class-4 driver, but they are not functionally different.
Switching from the thin driver to the oci driver is easy to configure. You only need to replace the connection string java: oracle: thin: @ hostip: 1521: Instance name with java: oracle: oci @ local service name. For example
Jdbc: oracle: thin: @ 10.1.1.2: 1521: shdb
Change
Jdbc: oracle: oci8: @ shdb
However, the server needs to install the oracle database client and configure the local service name. At the same time, you must specify the NLS_LANG environment variable, the NLS_LANG environment variable is used to control the character set and localization habits used by the client to display data in the oracle database. Generally, If you specify the NLS_LANG character set as the character set used by the database, java will not display garbled characters.
There are two options for installing the oracle database client. One is to use the oracle database installation CD to install the corresponding version of the oracle client. The second is to download the real-time client from which oracle is extracted. The real-time client does not need to be installed. Just unzip the downloaded package.
To enable java web to normally access oracle through the oci driver, you also need to configure relevant variables correctly on the client. The main features are as follows:
For windows and oracle clients:
1. Add % ORACLE_HOME % lib to the path environment variable.
2. Add % ORACLE_HOME % jdbclibclasses12.jar to the classpath environment variable. You can also copy classes12.jar to the commanlib directory of tomcat.
For windows and oracle Real-Time clients (assuming that the real-time client is decompressed on the d disk ):
1. Add d: instantclient_10_2 to the path environment variable.
2. Add d: instantclient_10_2classes12.jar to the classpath environment variable. You can also copy classes12.jar to the commanlib directory of tomcat.
For Linux systems and oracle clients:
1. Add the. bash_profile file in the user's home directory using tomcat
Exprot ORACLE_HOME =/u01/app/oracle/prodUCt/9.2.0.4
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib
2. Copy classes12.jar to the commanlib directory of tomcat.
For linux systems and oracle Real-Time clients:
1. Add the. bash_profile file in the user's home directory using tomcat
Exprot ORACLE_HOME =/instantclient_10_2
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib
2. Copy classes12.jar under the instantclient_10_2 directory to the commanlib directory of tomcat.
If a tomcat instance contains several applications that must be connected to the oracle database, do not place the oracle classes12.jar/zip file in the WEB-INF/lib directory of each application. Instead, put the classes12.jar/zip file in the common/lib directory of tomcat. Otherwise, the ojdbclib9/10 library will be reloaded.
Using the oracle Real-time client, you can create a tnsnames. ora directory under the instantclient_10_2 directory to add a connection string, for example:
SHDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.1.1.236) (PORT = 1521) (CONNECT_DATA = (SERVICE_NAME = shdb.