JDBC Improvements in Java 8

Last updated on Dec 27 2022
Prabhas Ramanathan

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

Table of Contents

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 90

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

Method Description
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

1. import java.sql.*; 
2. // implementing DriverAction interface 
3. class JdbcExample implements DriverAction{ 
4. // implementing deregister method of DriverAction interface 
5. @Override 
6. public void deregister() { 
7. System.out.println("Driver deregistered"); 
8. } 
9. public static void main(String args[]){ 
10. try{ 
11. // Creating driver instance 
12. Driver driver = new com.mysql.jdbc.Driver(); 
13. // Creating Action Driver 
14. DriverAction da = new JdbcExample(); 
15. // Registering driver by passing driver and driverAction 
16. DriverManager.registerDriver(driver, da); 
17. // Creating connection 
18. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","mysql"); 
19. //Here student is database name, root is username and password is mysql 
20. Statement stmt=con.createStatement(); 
21. // Executing SQL query 
22. ResultSet rs=stmt.executeQuery("select * from user"); 
23. while(rs.next()){ 
24. System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3)); 
25. } 
26. // Closing connection 
27. con.close(); 
28. // Calling deregisterDriver method 
29. DriverManager.deregisterDriver(driver); 
30. }catch(Exception e){ System.out.println(e);} 
31. } 
32. 
33. }

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.

Method Description
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 constant Description
public static final JDBCType ARRAY It identifies the generic SQL type ARRAY.
public static final JDBCType BIGINT It identifies the generic SQL type BIGINT.
public static final JDBCType BIT It identifies the generic SQL type BIT.
public static final JDBCType BLOB It identifies the generic SQL type BLOB.
public static final JDBCType BOOLEAN It identifies the generic SQL type BOOLEAN.
public static final JDBCType CHAR It identifies the generic SQL type CHAR.
public static final JDBCType CLOB It identifies the generic SQL type CLOB.
public static final JDBCType DATALINK It identifies the generic SQL type DATALINK.
public static final JDBCType DATE It identifies the generic SQL type DATE.
public static final JDBCType DECIMAL It identifies the generic SQL type DECIMAL.
public static final JDBCType DISTINCT It identifies the generic SQL type DISTINCT.
public static final JDBCType DOUBLE It identifies the generic SQL type DOUBLE.
public static final JDBCType FLOAT It identifies the generic SQL type FLOAT.
public static final JDBCType INTEGER It identifies the generic SQL type INTEGER.
public static final JDBCType JAVA_OBJECT It 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 LONGNVARCHAR It identifies the generic SQL type LONGNVARCHAR.
public static final JDBCType NCHAR It identifies the generic SQL type NCHAR.
public static final JDBCType NCLOB It identifies the generic SQL type NCLOB.
public static final JDBCType NULL It identifies the generic SQL value NULL.
public static final JDBCType NUMERIC It identifies the generic SQL type NUMERIC.
public static final JDBCType NVARCHAR It identifies the generic SQL type NVARCHAR.
public static final JDBCType OTHER It 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 REAL It identifies the generic SQL type REAL.Identifies the generic SQL type VARCHAR.
public static final JDBCType REF It identifies the generic SQL type REF.
public static final JDBCType REF_CURSOR It identifies the generic SQL type REF_CURSOR.
public static final JDBCType ROWID It identifies the SQL type ROWID.
public static final JDBCType SMALLINT It identifies the generic SQL type SMALLINT.
public static final JDBCType SQLXML It identifies the generic SQL type SQLXML.
public static final JDBCType STRUCT It identifies the generic SQL type STRUCT.
public static final JDBCType TIME It identifies the generic SQL type TIME.
public static final JDBCType TIME_WITH_TIMEZONE It identifies the generic SQL type TIME_WITH_TIMEZONE.
public static final JDBCType TIMESTAMP It identifies the generic SQL type TIMESTAMP.
public static final JDBCType TIMESTAMP_WITH_TIMEZONE It identifies the generic SQL type TIMESTAMP_WITH_TIMEZONE.
public static final JDBCType TINYINT It identifies the generic SQL type TINYINT.
public static final JDBCType VARBINARY It identifies the generic SQL type VARBINARY.
public static final JDBCType VARCHAR It identifies the generic SQL type VARCHAR.

JDBCType Methods

Method Description
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.

So, this brings us to the end of blog. This Tecklearn ‘JDBC Improvements in Java 8’ blog helps you with commonly asked questions if you are looking out for a job in Java Programming. If you wish to learn Java and build a career Java Programming domain, then check out our interactive, Java and JEE Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Java and JEE Training

Java and JEE Training

About the Course

Java and JEE Certification Training is designed by professionals as per the industrial requirements and demands. This training encompasses comprehensive knowledge on basic and advanced concepts of core Java & J2EE along with popular frameworks like Hibernate, Spring & SOA. In this course, you will gain expertise in concepts like Java Array, Java OOPs, Java Function, Java Loops, Java Collections, Java Thread, Java Servlet, and Web Services using industry use-cases and this will help you to become a certified Java expert.

Why Should you take Java and JEE Training?

• Java developers are in great demand in the job market. With average pay going between $90,000/- to $120,000/- depending on your experience and the employers.
• Used by more than 10 Million developers worldwide to develop applications for 15 Billion devices.
• Java is one of the most popular programming languages in the software world. Rated #1 in TIOBE Popular programming languages index (15th Consecutive Year)

What you will Learn in this Course?

Introduction to Java

• Java Fundamentals
• Introduction to Java Basics
• Features of Java
• Various components of Java language
• Benefits of Java over other programming languages
• Key Benefits of Java

Installation and IDE’s for Java Programming Language

• Installation of Java
• Setting up of Eclipse IDE
• Components of Java Program
• Editors and IDEs used for Java Programming
• Writing a Simple Java Program

Data Handling and Functions

• Data types, Operations, Compilation process, Class files, Loops, Conditions
• Using Loop Constructs
• Arrays- Single Dimensional and Multi-Dimensional
• Functions
• Functions with Arguments

OOPS in Java: Concept of Object Orientation

• Object Oriented Programming in Java
• Implement classes and objects in Java
• Create Class Constructors
• Overload Constructors
• Inheritance
• Inherit Classes and create sub-classes
• Implement abstract classes and methods
• Use static keyword
• Implement Interfaces and use it

Polymorphism, Packages and String Handling

• Concept of Static and Run time Polymorphism
• Function Overloading
• String Handling –String Class
• Java Packages

Exception Handling and Multi-Threading

• Exception handling
• Various Types of Exception Handling
• Introduction to multi-threading in Java
• Extending the thread class
• Synchronizing the thread

File Handling in Java

• Input Output Streams
• Java.io Package
• File Handling in Java

Java Collections

• Wrapper Classes and Inner Classes: Integer, Character, Boolean, Float etc
• Applet Programs: How to write UI programs with Applet, Java.lang, Java.io, Java.util
• Collections: ArrayList, Vector, HashSet, TreeSet, HashMap, HashTable

Java Database Connectivity (JDBC)

• Introduction to SQL: Connect, Insert, Update, Delete, Select
• Introduction to JDBC and Architecture of JDBC
• Insert/Update/Delete/Select Operations using JDBC
• Batch Processing Transaction
• Management: Commit and Rollback

Java Enterprise Edition – Servlets

• Introduction to J2EE
• Client Server architecture
• URL, Port Number, Request, Response
• Need for servlets
• Servlet fundamentals
• Setting up a web project in Eclipse
• Configuring and running the web app with servlets
• GET and POST request in web application with demo
• Servlet lifecycle
• Servlets Continued
• Session tracking and filter
• Forward and include Servlet request dispatchers

Java Server Pages (JSP)

• Fundamentals of Java Server Page
• Writing a code using JSP
• The architecture of JSP
• JSP Continued
• JSP elements: Scriptlets, expressions, declaration
• JSP standard actions
• JSP directives
• Introduction to JavaBeans
• ServletConfig and ServletContext
• Servlet Chaining
• Cookies Management
• Session Management

Hibernate

• Introduction to Hibernate
• Introduction to ORM
• ORM features
• Hibernate as an ORM framework
• Hibernate features
• Setting up a project with Hibernate framework
• Basic APIs needed to do CRUD operations with Hibernate
• Hibernate Architecture

POJO (Plain Old Java Object)

• POJO (Plain Old Java Object)
• Persistent Objects
• Lifecycle of Persistent Object

Spring

• Introduction to Spring
• Spring Fundamentals
• Advanced Spring

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

 

0 responses on "JDBC Improvements in Java 8"

Leave a Message

Your email address will not be published. Required fields are marked *