Difference Between Oracle Jdbc Driver Classes

Difference between Oracle jdbc driver classes?

For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.

-- http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html#Oracle_8i,9i&_10g

What is the actual use of Class.forName(oracle.jdbc.driver.OracleDriver) while connecting to a database?

It obtains a reference to the class object with the FQCN (fully qualified class name) oracle.jdbc.driver.OracleDriver.

It doesn't "do" anything in terms of connecting to a database, aside from ensure that the specified class is loaded by the current classloader. There is no fundamental difference between writing

Class<?> driverClass = Class.forName("oracle.jdbc.driver.OracleDriver");
// and
Class<?> stringClass = Class.forName("java.lang.String");

Class.forName("com.example.some.jdbc.driver") calls show up in legacy code that uses JDBC because that is the legacy way of loading a JDBC driver.

From The Java Tutorial:

In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method Class.forName. This methods required an object of type java.sql.Driver. Each JDBC driver contains one or more classes that implements the interface java.sql.Driver.

...

Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method Class.forName.)

Further reading (read: questions this is a dup of)

  • What purpose does Class.forName() serve if you don't use the return value?
  • How does Class.forName() work?
  • What does 'Class.forName("org.sqlite.JDBC");' do?
  • What is the purpose of 'Class.forName("MY_JDBC_DRIVER")'?
  • Loading JDBC driver

Understanding HikariCP/JDBC driver classnames vs data source classnames

In one case the connection is created through java.sql.DriverManager (or maybe even directly using the java.sql.Driver implementation), and you can only use the configuration properties the driver supports that way.

When using a data source, you're using an implementation of javax.sql.DataSource, and can only use the configuration properties the data source supports that way. If we're talking about driver-provided DataSource implementations, there generally is no difference. They usually offer the same (or similar) configuration properties, and produce exactly the same connection as they would return through their Driver implementation.

In theory, using a DataSource can have some benefits because of its programmatic configuration (instead of using properties in the URL or Properties object), and the fact you could have the DataSource sourced from some external configuration through JNDI or other means.

However, when configured through HikariCP, and specifically in the way as shown in your question, there is no substantial difference.

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

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

The OCI driver is a type 2 JDBC 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.

Oracle's JDBC Thin driver is a type 4 JDBC 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)

What is the relationship between the oracle.jdbc.OracleConnection interface and the T4CConnection class?

T4CConnection implements OracleConnection via the following inheritance hierarchy:
oracle.jdbc.driver.T4CConnection extends oracle.jdbc.driver.PhysicalConnection which extends oracle.jdbc.driver.OracleConnection which extends oracle.jdbc.OracleConnectionWrapper which implements oracle.jdbc.OracleConnection.

The error is likely a result of a class loading problem, where the Oracle classes are being loaded from multiple jars by different class loaders. These sources (1, 2, 3) discuss this in more detail.

Oracle Database 11g JDBC Drivers - So many files ??? What do they mean?

Sounds like you picked the right one.

The "_g" one would be needed if you needed to step through the Oracle JDBC code, which is unlikely.

The "dms" version supports fancier monitoring of the db. Again, not something you'd typically use.

"orai18n.jar" would be needed if you wanted to go whole hog with internationalization support.

xdb6.jar would be needed if you wanted to make use of SQLXML to store and process XML documents within the database.

The good news is ... if at any point you realize you do need any of these extra capabilities you can just swap out the jar and be on your way!



Related Topics



Leave a reply



Submit