This discussion is archived
5 Replies Latest reply: Dec 5, 2012 6:26 PM by 801904 RSS

Oracle JDBC choices: OCI or Thin (ojdbc6.jar), Oracle 11g R2, Java6-7 ?

801904 Newbie
Currently Being Moderated
Hello Everyone

I did a search on this forum regarding which Oracle JDBC driver to use (from the application servers) - the OCI-based or Thin JDBC and the topic has been covered a number of time but the answers were several years old (most recent in ~2008?) so I would like to resurrect this topic again, for the later versions of Java (1.7 or at least 1.6, using ojdbc6.jar or later) and using the latest version of Oracle 11g R2 (11.2.0.3) database and latest OCI 11g R2 client software.

Which JDBC solution is recommened for the latest versions of Java and Oracle - to use Thin driver or use OCI-based driver? And why so?

I have two scenarios:

(1) Java/JDBC application runs on separate (application) server to the database server. For example, Windows App Server with Java/JDBC and Oracle 11g R2 database server on Linux. This is similar to N-tier on-line application concept.

(2) Java/JDBC application runs on the same physical server where the database software is located, i.e. both the Java/JDBC and Oracle database run on Linux OS. This is similar to batch job concept.



Many thanks in advance
Yuri B
Melbourne
Australia
  • 1. Re: Oracle JDBC choices: OCI or Thin (ojdbc6.jar), Oracle 11g R2, Java6-7 ?
    801904 Newbie
    Currently Being Moderated
    I just found this:

    http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#02_01

    Which driver should I use?
    Use the Thin driver unless there is a reason to use something else.

    If you are writing an applet, you must use the Thin driver.

    If you are using a non-TCP/IP network you must use the OCI driver.

    If you are running in the Oracle server, then you should use the Server Internal Driver unless you need to connect to another Oracle database server or to open a second session on the same server. In either of these cases you should use the Server Thin Driver.

    Generally the Thin driver is the best choice. In most cases it is as fast or faster than the OCI driver (from 10.1.0), has almost exactly the same set of features, and is easier to administer. In a few cases the OCI driver has slightly better performance. The OCI driver supports a few Oracle features better than the Thin driver. The Thin driver is easier to administer since it does not require installation of the OCI C libraries. The Thin driver will work on any machine that has a suitable Java VM, whereas with the OCI driver you must install the proper OCI C libraries for each machine. We recommend using the Thin driver unless you must have one or more of the OCI only features, or until it is clear that the small performance gain provided by the OCI driver is worth the extra effort.

    -----------

    I guess this answers my question? Anything else to add to the above?

    thanks
  • 2. Re: Oracle JDBC choices: OCI or Thin (ojdbc6.jar), Oracle 11g R2, Java6-7 ?
    rp0428 Guru
    Currently Being Moderated
    >
    Which JDBC solution is recommened for the latest versions of Java and Oracle - to use Thin driver or use OCI-based driver? And why so?

    I have two scenarios:

    (1) Java/JDBC application runs on separate (application) server to the database server. For example, Windows App Server with Java/JDBC and Oracle 11g R2 database server on Linux. This is similar to N-tier on-line application concept.

    (2) Java/JDBC application runs on the same physical server where the database software is located, i.e. both the Java/JDBC and Oracle database run on Linux OS. This is similar to batch job concept.
    >
    See Introduction JDBC in the JDBC Dev Guide
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/overvw.htm#CJAHEFFI
    >
    Oracle provides the following JDBC drivers:
    •Thin driver
    It is a pure Java driver used on the client-side, without an Oracle client installation. It can be used with both applets and applications.
    •Oracle Call Interface (OCI) driver
    It is used on the client-side with an Oracle client installation. It can be used only with applications.
    •Server-side Thin driver
    It is functionally similar to the client-side Thin driver. However, it is used for code that runs on the database server and needs to access another session either on the same server or on a remote server on any tier.
    •Server-side internal driver
    It is used for code that runs on the database server and accesses the same session. That is, the code runs and accesses data from a single Oracle session.
    >
    #1 - use the thin driver
    #2 - use the Server-side thin driver

    REMEMBER - the Oracle DB currently ships with, uses AND MUST USE Java 1.5. You cannot update the DB version used internally and you cannot disable it without breaking the DB. So don't try to import code that requires features only found in later Java versions.

    Only driver exception would be if you need any OCI specific features as discussed in the same JDBC Dev Guide
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/instclnt.htm#CHDCJEDD
    >
    This chapter introduces the features specific to the Java Database Connectivity (JDBC) Oracle Call Interface (OCI) driver. It also describes the OCI Instant Client. This chapter contains the following sections:
    •OCI Connection Pooling
    •Client Result Cache
    •Transparent Application Failover
    •OCI Native XA
    •OCI Instant Client
    •Instant Client Light (English)
    >
    So my final recommendation is to use the standard (client-side) thin driver in all cases:

    1. use of only one driver is a better standard unless you actually validate a need for a 2nd driver. Only one common connection string type to use for all software. Easier on the developers to keep things straight.

    2. use of only one driver minimizes the chance of a bug in one of the drivers causing a problem. All drivers are in the same jar file. Oracle, of course, tries to makes sure that their common features are as identical or compatible as possible but whenever you have multiple 'anything' their is always a chance something doesn't work the same way in each driver.
  • 3. Re: Oracle JDBC choices: OCI or Thin (ojdbc6.jar), Oracle 11g R2, Java6-7 ?
    801904 Newbie
    Currently Being Moderated
    many thanks!

    re Oracle 11g R2 DB and Java 1.5 requirement.
    Thanks for the tip, this is indeed a trap as even Java 1.6 has been around long enough (several years?) for Oracle database folks to get their act together and support it inside the database engine.

    Let me ask one more question please.

    Let us suppose that I developed some Java class/methods using NetBeans and have used Java 1.7 (or 1.6) JDK.

    Also suppose that I did not use any new Java 1.6 or 1.7 features in any of my classes, i.e. my class/methods were compatible with Java 1.5 but were created/compiled with later versions of Java, i.e. 1.6/1.7.

    Question: what is the supported process of loading my Java class/methods into Oracle 11g R2 database in this case?

    Do I need to install older Java 1.5 (which update of 1.5?) on my development workstation, along-side with Java 1.6/1.7 and then compile all my code using JDK 1.5 and then load the classes/jars into Oracle 11g R2 database?
    Or can I load the classes compiled with Java 1.6/1.7 into Oracle 11g R2 database and JVM 1.5 will do the right thing?

    many thanks in advance
    YuriB
  • 4. Re: Oracle JDBC choices: OCI or Thin (ojdbc6.jar), Oracle 11g R2, Java6-7 ?
    rp0428 Guru
    Currently Being Moderated
    >
    Let us suppose that I developed some Java class/methods using NetBeans and have used Java 1.7 (or 1.6) JDK.

    Also suppose that I did not use any new Java 1.6 or 1.7 features in any of my classes, i.e. my class/methods were compatible with Java 1.5 but were created/compiled with later versions of Java, i.e. 1.6/1.7.

    Question: what is the supported process of loading my Java class/methods into Oracle 11g R2 database in this case?

    Do I need to install older Java 1.5 (which update of 1.5?) on my development workstation, along-side with Java 1.6/1.7 and then compile all my code using JDK 1.5 and then load the classes/jars into Oracle 11g R2 database?
    Or can I load the classes compiled with Java 1.6/1.7 into Oracle 11g R2 database and JVM 1.5 will do the right thing?
    >
    There are class file differences between versions. Some differences (post 1.4) are major and prevent an earlier version of the JVM from being able to run class files created in later versions. For example you cannot execute 1.6 class files in 1.4.

    Other differences are minor or related to functionality that isn't available in an older release. If a class file uses functionality that requires supporting classes in the JDK the earlier version of the JDK may not have those support classes, or may have a different version of them.

    If you need to load Java into the database the safest way is to load the source files. Then they will be compiled by DB version of Java and if they don't use features from later versions they will compile cleanly and produce the appropriate class files.

    If you load class files that are compiled using a version of Java later than the DB version (DB version is currently 1.5) those classes should be compiled using the '-target 1.5' command-line parameter. That will ensure that the class files created are compatible with Java 1.5
  • 5. Re: Oracle JDBC choices: OCI or Thin (ojdbc6.jar), Oracle 11g R2, Java6-7 ?
    801904 Newbie
    Currently Being Moderated
    thank you very much.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points