Java 8 JDBC Improvements

In Java 8, Java made two major changes in JDBC API.

1) The JDBC-ODBC Bridge has been removed.

Oracle does not support the JDBC-ODBC Bridge. Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge.

2) Added some new features in JDBC 4.2.

Java JDBC 4.2 introduces the following features:

  • Addition of REF_CURSOR support.
  • Addition of java.sql.DriverAction Interface
  • Addition of security check on deregisterDriver Method in DriverManager Class
  • Addition of the java.sql.SQLType Interface
  • Addition of the java.sql.JDBCType Enum
  • Add Support for large update counts
  • Changes to the existing interfaces
  • Rowset 1.2: Lists the enhancements for JDBC RowSet.
Java 8 JDBC Improvements

Java JDBC DriverAction

It is an interface that must be implemented when a Driver wants to be notified by DriverManager. It is added in java.sql package and contains only one abstract method.

DriverAction Method

MethodDescription
void deregister()This method called by DriverManager.deregisterDriver(Driver) to notify the JDBC driver that it was de-registered.

The deregister method is intended only to be used by JDBC Drivers and not by applications.

JDBC drivers are recommended not to implement the DriverAction in a public class.

If there are active connections to the database at the time that the deregister method is called, it is implementation specific as to whether the connections are closed or allowed to continue. Once this method is called, it is implementation specific as to whether the driver may limit the ability to create new connections to the database, invoke other Driver methods or throw a SQLException.


Java JDBC4.2 DriverAction Example

Output:

1  Arun  25
2  irfan  22
3  Neraj kumar  25
Driver deregistered

Java JDBC SQLType

This interface is used to identify a generic SQL type, JDBC type or a vendor specific data type.

It provides following methods.

MethodDescription
String getName()It returns the SQLType name that represents a SQL data type.
String getVendor()It returns the name of the vendor that supports this data type. The value returned typically is the package name for this vendor.
Integer getVendorTypeNumber()It returns the vendor specific type number for the data type.

Java JDBCType

It is an Enumeration which defines the constants that are used to identify generic SQL types, called JDBC types. It extends java.lang.Enum and implements java.sql.SQLType.

JDBCType Fields

The following table contains constants defined in the JDBCType.

Enum constantDescription
public static final JDBCType ARRAYIt identifies the generic SQL type ARRAY.
public static final JDBCType BIGINTIt identifies the generic SQL type BIGINT.
public static final JDBCType BITIt identifies the generic SQL type BIT.
public static final JDBCType BLOBIt identifies the generic SQL type BLOB.
public static final JDBCType BOOLEANIt identifies the generic SQL type BOOLEAN.
public static final JDBCType CHARIt identifies the generic SQL type CHAR.
public static final JDBCType CLOBIt identifies the generic SQL type CLOB.
public static final JDBCType DATALINKIt identifies the generic SQL type DATALINK.
public static final JDBCType DATEIt identifies the generic SQL type DATE.
public static final JDBCType DECIMALIt identifies the generic SQL type DECIMAL.
public static final JDBCType DISTINCTIt identifies the generic SQL type DISTINCT.
public static final JDBCType DOUBLEIt identifies the generic SQL type DOUBLE.
public static final JDBCType FLOATIt identifies the generic SQL type FLOAT.
public static final JDBCType INTEGERIt identifies the generic SQL type INTEGER.
public static final JDBCType JAVA_OBJECTIt indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject.
Public static final JDBCType LONGNVARCHARIt identifies the generic SQL type LONGNVARCHAR.
public static final JDBCType NCHARIt identifies the generic SQL type NCHAR.
public static final JDBCType NCLOBIt identifies the generic SQL type NCLOB.
public static final JDBCType NULLIt identifies the generic SQL value NULL.
public static final JDBCType NUMERICIt identifies the generic SQL type NUMERIC.
public static final JDBCType NVARCHARIt identifies the generic SQL type NVARCHAR.
public static final JDBCType OTHERIt indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject.
public static final JDBCType REALIt identifies the generic SQL type REAL.Identifies the generic SQL type VARCHAR.
public static final JDBCType REFIt identifies the generic SQL type REF.
public static final JDBCType REF_CURSORIt identifies the generic SQL type REF_CURSOR.
public static final JDBCType ROWIDIt identifies the SQL type ROWID.
public static final JDBCType SMALLINTIt identifies the generic SQL type SMALLINT.
public static final JDBCType SQLXMLIt identifies the generic SQL type SQLXML.
public static final JDBCType STRUCTIt identifies the generic SQL type STRUCT.
public static final JDBCType TIMEIt identifies the generic SQL type TIME.
public static final JDBCType TIME_WITH_TIMEZONEIt identifies the generic SQL type TIME_WITH_TIMEZONE.
public static final JDBCType TIMESTAMPIt identifies the generic SQL type TIMESTAMP.
public static final JDBCType TIMESTAMP_WITH_TIMEZONEIt identifies the generic SQL type TIMESTAMP_WITH_TIMEZONE.
public static final JDBCType TINYINTIt identifies the generic SQL type TINYINT.
public static final JDBCType VARBINARYIt identifies the generic SQL type VARBINARY.
public static final JDBCType VARCHARIt identifies the generic SQL type VARCHAR.

JDBCType Methods

MethodDescription
public String getName()It returns the SQLType name that represents a SQL data type.
public String getVendor()It returns the name of the vendor that supports this data type.
public Integer getVendorTypeNumber()It returns the vendor specific type number for the data type.
public static JDBCType valueOf(int type)It returns the JDBCType that corresponds to the specified Types value. It throws IllegalArgumentException, if this enum type has no constant with the specified Types value.
public static JDBCType valueOf(String name)It returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. It throws IllegalArgumentException, if this enum type has no constant with the specified name. It throws NullPointerException, if the argument is null.
public static JDBCType[] values()It returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants.




Latest Courses