New Features in JDBC 4.0
Java database connectivity (JDBC) is the Java Soft
specification of the API. It allows Application Programs to interact with the Database to access the Relational Data. Typically the JDBC API consists of a set of interfaces and classes written in the Java programming language. The applications can be written to connect to databases using these standard interfaces and classes and also to process the results by sending queries written in SQL. Furthermore the back-end Database session can be connected by JDBC API which can execute the Queries to get the Results.
The three most important features of Driver and Connection Management in JDBC are described below with some new features and enhancements.
1. Getting Connected Becomes Easier
This is one of the most important feature in JDBC that has relieved the developers from loading the driver explicitly. Exactly, you got it right, no need to explicitly load the driver by calling Class.forName anymore. So from now on don't bother to load the driver because the DriverManager will automatically load the driver found in the application CLASSPATH while your application tries to connect the database for the first time. However it is still preferred to create an appropriate DataSource object to retrieve a connection. Since the properties of data source instance can be modified which allows portability and transparency, there is no need to modify any application code to connect to a different database instance. Hence to retrieve a connection there is no need to change any application code to connect to a different database instance that requires loading a different driver.
For example: Earlier the programmers used to
manually load the drivers before making any Database Calls. The code which was
used by the programmers is:
The disadvantage is that the code will be changed if the Database Driver vendor wants to change the class name. Now this problem doesn't persist anymore. With the help of Service Provider Mechanism available from Java 5, the Driver will be Loaded Automatically by the JVM provided that the Jar files corresponding to the Driver Class are in the appropriate class path.
To understand this mechanism consider two entities, one is the service which contains a set of interfaces and the other entity is the provider who gives a well-defined Implementation for the Service. Now to maintain a directory structure, this service is packaged as a Jar by the provider. The structure of a directory is:
Rememeber the file should only contain one entry that is the Name of the Provider Class. The function of this entry is to implement the Driver. Also the name of the file is java.sql.Driver in the above code. For instance the content of the file in My SQL would be,
File - Java.sql.Driver
2. Using ResultSet Becomes More Flexible
Several important features of ResultSet interfaces hierarchy are described below: