Three different types of JDBC drivers in Oracle Database

Source: Internet
Author: User

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:

 
 
  1. jdbc:Oracle :thin:@server ip: service  
  2. 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.

 
 
  1. How does one connect with the JDBC OCI Driver?  
  2. One must have Net8 (SQL*Net) installed and working before attempting to use one of the OCI drivers.  
  3. Code: [Copy to clipboard]  
  4. import java.sql.*;  
  5. class dbAccess {  
  6. public static void main (String args []) throws SQLException  
  7. {  
  8. try {  
  9. Class.forName ("Oracle .jdbc.driver.Oracle Driver");  
  10. } catch (ClassNotFoundException e) {  
  11. e.printStackTrace();  
  12. }  
  13. Connection conn = DriverManager.getConnection  
  14. ("jdbc:Oracle :oci8:@ORA1", "scott", "tiger");  
  15. // or oci9 @Service, userid, password  
  16. Statement stmt = conn.createStatement();  
  17. ResultSet rset = stmt.executeQuery (  
  18. "select BANNER from SYS.V_$VERSION"  
  19. );  
  20. while (rset.next())  
  21. System.out.println (rset.getString(1)); // Print col 1  
  22. stmt.close();  
  23. }  
  24. }  
  25. How does one connect with the JDBC KPRB Driver?  
  26. 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 .  
  27. import java.sql.*;  
  28. Code: [Copy to clipboard]  
  29. class dbAccess {  
  30. public static void main (String args []) throws SQLException  
  31. {  
  32. Connection conn = (new  
  33. Oracle .jdbc.driver.Oracle Driver()).defaultConnection();  
  34. Statement stmt = conn.createStatement();  
  35. ResultSet rset = stmt.executeQuery (  
  36. "select BANNER from SYS.V_$VERSION"  
  37. );  
  38. while (rset.next())  
  39. System.out.println (rset.getString(1)); // Print col 1  
  40. stmt.close();  
  41. }  
  42. }   

The above content is an introduction to the three types of JDBC drivers in the Oracle database. I hope you will find some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.