The following articles mainly introduce three different types of JDBC drivers in Oracle databases. We all know that jdbc drivers in Oracle mainly include the following three types: 1. jdbc oci: oci is the abbreviation of Oracle call interface, which is similar to the traditional ODBC driver.
Because it requires Oracle Call Interface and Net8, it needs to install the client software on the machine that runs the JAVA program using this driver, in fact, it mainly uses the oci and server configuration provided in dll mode in the orcale client.
2. JDBC Thin: thin is the meaning of for thin client, which is generally used in JAVA programs running in WEB browsers. It does not communicate through OCI or Net8, but through Java sockets, and is a pure java-implemented driver. Therefore, you do not need to install orcale client software on the client machine that uses JDBC Thin, therefore, it has good portability and is usually used in web development.
3. jdbc kprb: This type of driver is used by JAVA programs directly Stored in the Database, such as Java Stored Procedures, triggers, and Database JSP's. Because it is used inside the server, it uses the default or current session to connect to the database, without the user name and password or the database url.
During application development, the first two methods are usually used. The following is the writing method of the Database url:
- jdbc:Oracle :thin:@server ip: service
- jdbc:Oracle :oci:@service
It seems that the oci is more concise, and the ip address can be omitted, because the oci driver uses the native java methods of the client to access the database server in the c library mode, use the database service configuration in the net manager of the client.
Because the oci method eventually communicates with the database server using the c library, the theoretical performance is superior to the thin method. It is said that it is mainly reflected in the access of blob fields.
Pl SQL dev, which is often used for Oracle database development, is estimated to be in the oci mode. You need to install the client, but you can also choose not to install it, however, you need to extract the oci-related dll (jar package), register environment variables, and configure the listener file. Oracle provides a streamlined client after 10 Gb. The installation process should include the above work.
- How does one connect with the JDBC OCI Driver?
- One must have Net8 (SQL*Net) installed and working before attempting to use one of the OCI drivers.
- Code: [Copy to clipboard]
- import java.sql.*;
- class dbAccess {
- public static void main (String args []) throws SQLException
- {
- try {
- Class.forName ("Oracle .jdbc.driver.Oracle Driver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Connection conn = DriverManager.getConnection
- ("jdbc:Oracle :oci8:@ORA1", "scott", "tiger");
- // or oci9 @Service, userid, password
- Statement stmt = conn.createStatement();
- ResultSet rset = stmt.executeQuery (
- "select BANNER from SYS.V_$VERSION"
- );
- while (rset.next())
- System.out.println (rset.getString(1)); // Print col 1
- stmt.close();
- }
- }
- How does one connect with the JDBC KPRB Driver?
- One can obtain a handle to the default or current connection
(KPRB driver) by calling the Oracle Driver.defaultConenction() method.
Please note that you do not need to specify a database URL,
username or password as you are already connected to a database session.
Remember not to close the default connection.
Closing the default connection might throw an exception in future releases of Oracle .
- import java.sql.*;
- Code: [Copy to clipboard]
- class dbAccess {
- public static void main (String args []) throws SQLException
- {
- Connection conn = (new
- Oracle .jdbc.driver.Oracle Driver()).defaultConnection();
- Statement stmt = conn.createStatement();
- ResultSet rset = stmt.executeQuery (
- "select BANNER from SYS.V_$VERSION"
- );
- while (rset.next())
- System.out.println (rset.getString(1)); // Print col 1
- stmt.close();
- }
- }
The above content is an introduction to the three types of JDBC drivers in the Oracle database. I hope you will find some gains.