java和oracle XE之间的数据源连接与OCI和THIN驱动程序连接有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21711085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:12:49  来源:igfitidea点击:

What is the difference between OCI and THIN driver connection with data source connection between java and oracle XE?

javaoraclejdbcdatabase-connection

提问by Tofiq

I'm writing the below codes for connection between the java and Oracle 10g XE using 3 way(OCI, THIN and data source), the code is running successfully but don't know difference between the THIN and OCI with data source connection.

我正在使用 3 种方式(OCI、THIN 和数据源)编写 java 和 Oracle 10g XE 之间的连接代码,代码运行成功,但不知道 THIN 和 OCI 与数据源连接之间的区别。

1-

1-

public static void main (String args[]) throws SQLException
 {
  OracleDataSource ods = new OracleDataSource();
  ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
  Connection con = ods.getConnection();
  System.out.println("Connected");
  con.close();
 }

2-

2-

public static void main(String args[])
     {
      try
      {
       // load oracle driver
      Class.forName("oracle.jdbc.driver.OracleDriver");
      // connect using Thin driver
      Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
      System.out.println("Connected Successfully To Oracle");
      con.close();
      }
      catch(Exception ex)
      {
        ex.printStackTrace();
      }
 }

3-

3-

public static void main(String args[])
     {
      try
      {
       // load oracle driver
      Class.forName("oracle.jdbc.driver.OracleDriver");
      // connect using Native-API (OCI) driver
      Connection con = DriverManager.getConnection("jdbc:oracle:oci:@","hr","hr" );
      System.out.println("Connected Successfully To Oracle using OCI driver");
      con.close();
      }
      catch(Exception ex)
      {
        ex.printStackTrace();
      }
 }

采纳答案by Elliott Frisch

Oracle provides four types of drivers for their database, but I'll only enumerate the two you asked about.

Oracle 为其数据库提供了四种类型的驱动程序,但我只会列举您询问的两种。

The OCIdriver is a type 2JDBC driver and uses native code to connect to the database. Thus, it is only an option on platforms that have native Oracle drivers available and it is not a "pure" Java implementation.

所述OCI驱动器是2型JDBC驱动器和使用本地代码来连接到数据库。因此,它只是具有可用本机 Oracle 驱动程序的平台上的一个选项,而不是“纯”Java 实现。

Oracle's JDBC Thin driver is a type 4JDBC Driver that uses Java sockets to connect directly to Oracle. It implements Oracle's SQL*Net TCP/IP protocol directly. Because it is 100% Java, it is platform independent and can also run from an Applet. (not that you should)

Oracle 的 JDBC 瘦驱动程序是4 类JDBC 驱动程序,它使用 Java 套接字直接连接到 Oracle。它直接实现了 Oracle 的 SQL*Net TCP/IP 协议。因为它是 100% Java,所以它是独立于平台的,也可以从 Applet 运行。(不是你应该的)

回答by Jean de Lavarene

Both the JDBC thin driver and the JDBC OCI driver speak the same network protocol. From the server standpoint there is no difference between the two. The JDBC thin driver is 100% Java and comes in a single standalone jar (some extra jars will be needed for advanced features). The JDBC OCI driver makes JNI calls to the OCI C client library and hence depends on the Oracle full client to be installed (OCI is also what sqlplus uses). Oracle recommends to use the JDBC thin driver which is what most customers use. It's the fastest driver and the most robust one.

JDBC 瘦驱动程序和 JDBC OCI 驱动程序都使用相同的网络协议。从服务器的角度来看,两者之间没有区别。JDBC 瘦驱动程序是 100% Java 并包含在一个独立的 jar 中(高级功能需要一些额外的 jar)。JDBC OCI 驱动程序对 OCI C 客户端库进行 JNI 调用,因此依赖于要安装的 Oracle 完整客户端(OCI 也是 sqlplus 使用的)。Oracle 建议使用大多数客户使用的 JDBC 瘦驱动程序。它是最快的驱动程序,也是最强大的驱动程序。