➤ Intro to JDBC
➤ JDBC vs ODBC
➤ JDBC API
➤ JDBC Driver
Connect to Database
➤ Oracle Connection
➤ MySQL Connection
➤ Using Eclipse IDE
➤ Coding Standards
➤ Close JDBC Object
➤ Java.sql Package
➤ DriverManager Class
➤ Get Connection
➤ Statement Interface
➤ Statement Example
➤ Create a database
➤ Types of statements
➤ Statement vs PreParedStatement
➤ Insert record
➤ Update record
➤ Select record
➤ Create a table
➤ More Examples
➤ Surrogate Key
➤ ResultSetMetaData & ParameterMetaData
Previously we learned the Introduction to JDBC, the difference between JDBC and ODBC. All vendor companies created JDBC drivers based on common rules and guidelines of JDBC technology or JDBC API. There are many versions of the JDBC driver API. Here we will discuss the different JDBC API version and their features. What is the latest JDBC driver API version?
The Java Database Connectivity (JDBC) API is the industry standard for database-independent connectivity between the Java programming language and a wide range of databases—SQL databases and other tabular data sources, such as spreadsheets or flat files. The JDBC API provides a call-level API for SQL-based database access.
JDBC technology allows us to use the Java programming language to exploit “Write Once, Run Anywhere” capabilities for applications that require access to enterprise data. With a JDBC technology-enabled driver, we can connect all corporate data even in a heterogeneous environment.
JDBC Driver API
JDBC is a Java-based software technology/specification providing JDBC API having a set of rules and guidelines to develop JDBC driver software by using Java language. Working with JDBC driver software is nothing but working JDBC technology which is not installable but we can arrange JDBC driver software as jar files. The Java class that implements java.sql.Driver(I) directly or indirectly is called JDBC driver class.
The JDBC driver API versions are,
JDBC 1.0 API
JDBC 1.2 API
JDBC 2.0 Optional Package API
JDBC 2.1 Core API
JDBC 3.0 API
JDBC 4.0 API
JDBC 4.1 API
JDBC 4.2 API
JDBC 4.3 API
The JDBC 4.3 is the latest version of JDBC technology.
Table for JDBC version, its JDK implementation, and releases year with JSR Specification
|JDBC 1.0 API||JDK 1.0||1996||—|
|JDBC 1.2 API||JDK 1.1||1997||—|
|JDBC 2.0 |
Optional Package API
|JDBC 2.1 Core API||JDK 1.2||1999||—|
|JDBC 3.0 API||J2SE 1.4||2001||JSR 54|
|JDBC 4.0 API||Java SE 6||2006||JSR 221|
|JDBC 4.1 API||Java SE 7||2011||JSR 221|
|JDBC 4.2 API||Java SE 8||2014||JSR 221|
|JDBC 4.3 API||Java SE 9||2017||JSR 221|
The JDBC technology will not give rules and guidelines as English statements, They will be given as APIs.
- The interface of the technology API represents only rules (Upto Java7).
- The abstract classes of the technology API represent both rules and guidelines.
- The concrete classes of the technology API represent only guidelines.
How interface, abstract class, and concrete class can provide rules and guidelines? Well, whenever we extend a class from an abstract class then all its abstract methods must be implemented (rule) and other methods can be overridden (guidelines). The concrete class has only the concrete methods so it provides guidelines only. Up to Java7, the interface had only a method declaration that provides rules, but from Java8 the interfaces can have method implementation also, therefore it provides both rules and guidelines.
Database and JDBC API Version
The below table lists the Oracle JDBC drivers and the JDBC specification supported in that release.
|Oracle Database |
|11.2 or 11gR2||Sep 2009||JDBC 3.0 in ojdbc5.jar with JDK5|
JDBC 4.0 in ojdbc6.jar with JDK 6, JDK 7, and JDK 8
|12.1 or 12cR1||Jun 2013||JDBC 4.0 in ojdbc6.jar with JDK 6|
JDBC 4.1 in ojdbc7.jar with JDK 7, and JDK 8
|12.2 or 12cR2||Mar 2017||JDBC 4.2 in ojdbc8.jar with JDK 8|
|18.3||July 2018||JDBC 4.2 in ojdbc8.jar with JDK 8, JDK 9, with JDK10, JDK11|
|19.3||Apr 2019||JDBC 4.2 in ojdbc8.jar with JDK8, JDK9, JDK10, JDK11|
JDBC 4.3 in ojdbc10.jar with JDK10, JDK11
Table for MySQL database connector and JDBC driver API version.
|MySQL Server |
|5.1||3.0, 4.0, 4.1, 4.2||5.6, 5.7, 8.0||JDK 5, JDK 8 or higher|
|8.0||4.2||5.6, 5.7, 8.0||JDK 8 or higher|
Features of JDBC 1.x and 2.x API
No need to remember the features of different versions of JDBC API, just look them once.
Features of JDBC driver 1.0 API version
- The JDBC 1.0 API was the first officially JDBC API launched consists of the following Java classes and interfaces that we can open connections to particular databases.
- This version includes a completely redesigned administration console with an enhanced graphical interface to manage and monitor distributed virtual databases.
Features of JDBC driver 1.2 API version
- It supports Updatable ResultSets.
- The DatabaseMetaData code has been refactored to provide more transparency with regard to the underlying database engine.
- New Pass-through schedulers for increased performance.
Features of the JDBC 2.0 Optional Package API
- The use of DataSource interface for making a connection.
- Use of JNDI to specify and obtain database connections.
- It allows us to use Pooled connections. Due to this features we can reuse the connection.
- In this version the distributed transactions is possible.
- It provides a way of handling and passing data using Rowset technology.
Features of the JDBC 2.1 core API
- Scroll forward and backward in a result set or has the ability to move to a specific row.
- Instead of using SQL commands, we can make updates database tables using methods in the Java programming language.
- We can use multiple SQL statements in a database as a unit, or batch.
- It uses the SQL3 datatypes as column values. SQL3 types are Blob, Clob, Array, Structured type. Ref.
- It increased the support for storing persistent objects in the Java programming language.
- It supports for the time zones in date, time, and Timestamp values.
- Full precision for java.math.BigDecimal values.
Features of JDBC driver 3.0 API version
- Reusability of prepared statements by connection pools.
- In this version, there is a number of properties defined for the ConnectionPoolDataSource. These properties can be used to describe how the PooledConnection objects created by DataSource objects should be pooled.
- A new concept has been added to this API of savepoints. One of the useful new features is transactional savepoints. With JDBC 3.0 the transactional model is now more flexible.
- Retrieval of parameter metadata.
- It has added a means of retrieving values from columns containing automatically generated values.
- Added a new data type i.e. java.sql.BOOLEAN
- Passing parameters to CallableStatement
- The data in the Blob and Clob can be altered. JDBC 3.0 introduces a standard mechanism for updating BLOB and CLOB data.
- DatabaseMetaData API has been added.
- It allows stored procedure parameters to be called by name.
Features of JDBC 4.0 API Version
It supports the autoloading of JDBC driver class. In JDBC 4.0 after invoking the getConnection() method on DriverManger, it will automatically load the JDBC driver class. For example, In the case of the Oracle database (with JDK1.8+ version), it will automatically load oracle.jdbc.OracleDriver class.
- Connection management enhancements. In JDBC it may happen that a Connection is lying idle or not closed in a pool, then it becomes stale over time. This will lead to the connection pool run out of resources due to a stale connection.
- It supports for RowId data type. JDBC introduces support for ROWID, a data type that had been using in database products even before it became part of the SQL.
- SQL exception handling enhancements. The JDBC 4.0 addresses the error handling beautifully. As databases are often remotely accessible resources, problems such as network failures are common and it can cause exceptions when executing a database operation. SQL statements can also cause exceptions. Prior to JDBC 4.0, most JDBC operations generated a simple SQLException.
- DataSet implementation of SQL using Annotations. The JDBC 4.0 specification leverages annotations to allow developers to associate a SQL query with a Java class without a need to write a lot of code to achieve this association.
- SQL XML support.
How to check JDBC supports auto-loading of driver class on not?
Open jar file of JDBC driver, go to META-INF/services folder, and open the “java.sql.Driver” file with any text editor software. If it contains the driver class name then the JDBC driver supports the auto-loading of the driver class.
|Database||Driver Class Name |
Features of JDBC 4.1, 4.2, and 4.3 API Versions
Main new features introduced in JDBC 4.1 API version are,
- Added support for try-with-resources statements
- Enhanced Date.valueOf and Timestamp.valueOf
- Additional Mappings from Java Object to JDBC Types
- Some JDBC API changes
Main new features introduced in JDBC 4.2 are,
- Added support for REF CURSOR
- Some JDBC API changes
- The following interfaces are added:- java.sql.DriverAction interface, java.sql.SQLType interface, and java.sql.JDBCType Enum
Main new features introduced in JDBC 4.3 are,
- Added support for Sharding
- The following interface are added:- java.sql.ConnectionBuilder interface, java.sql.ShardigKey interface, java.sql.ShardingKeyBuilder interface, javax.sql.XAConnectionBuilder interface, javax.sql.PooledConnectionBuilder interface
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!