Java 7 JDBC Improvements
JDBC (Java Database Connectivity) provides universal data access from the Java programming language. You can access any data from database, spreadsheets or flat files by using JDBC.
In Java 7, Java has introduced the following features:
1) It provides the ability to use a try-with-resources statement to automatically close resources of type Connection, ResultSet, and Statement.
2) RowSet 1.1: The introduction of the RowSetFactory interface and the RowSetProvider class, which enable you to create all types of row sets supported by your JDBC driver.
It defines the implementation of a factory that is used to obtain different types of RowSet.
RowSetFactory Interface Methods
Java RowSetProvider Class
It is a factory API that helps to applications to get a RowSetFactory implementation that can be used to create different types of RowSet.
JDBC Example: Mysql Connection by using Try-With-Resources
In the above example, we have used try-with-resources. It is used to close resources after completing try block. Now, you don't need to close database connection explicitly.
Make sure you are using JDBC version 4.0 or higher and Java version 1.6 or higher.
In earlier versions of Java, you have created instances of JdbcRowSet, CachedRowSet, FilteredRowSet etc by using JdbcRowSetImpl class.
Now, Java 7 has added a new RowSet 1.1. So, you can create instance of JdbcRowSet by using RowSetFactory interface.
Itstores (caches) data into memory so that is can perform operations on its own data rather than data stored in the database. It can operate without being connected to its data source, that why, it is also known as disconnectedRowSet.
Java JDBC Example: CachedRowSet
It is an improvedResultSet object which is used to maintain connection to a data source. It is similar to ResultSet, but the big difference is that it provides set of properties and listener like a JavaBeans.The main purpose of JdbcRowSet is to make a ResultSet scrollable and updatable.
In the following example, we are creating instance of JdbcRowSet by using new approach.
Java JdbcRowSet Example 1
Java JdbcRowSet Example: Updating Row
3 Neraj kumar 8562697858 3 Neraj Kumar Singh 8562697858