http://www.artima.com/lejava/articles/jdbc_four.html
Version 4 of the JDCB API is currently in Early Draft Review in the JCP (JSR 221). Here’s my recapitulation of the article:
1. Better Pools
– Connection.isValid() method is added.
– poolable property to hint some statements prefer to be pooled.
– A new way of jdbc driver loading via META-INF/services/java.sql.driver file.
2. SQL 2003 Support
– ROWID support.
– BLOB, CLOB, NCLOB, ARRAY, Structured Type, REF, DISTINCT, and DATALINK datatype.
3. XML as a First-Class SQL Data Type
– SQLXML Datatype is provided with StAX.
– XMLELEMENT support to serialize data into XML format using SQL.
4. Exceptional exceptions
– SQLException are subdivided into SQLTransientExceptions and SQLNonTransientExceptions. Both of them are also subdivided into more fine grained exceptions.
5. Type-safe querying and results (I love this feature.)
– @Query annotation was added. Using this annotation, u can do like:
Declaring entity.
interface MyQueries extends BaseQuery {
@Query(sql=”select * from user”)
DataSet getAllUsers();
}
To get the data from DB,
Connection c = myDataSource.getConnection();
MyQueries myQueries = c.createQueryObject(MyQuery.class);
DataSet users = myQueries.getAllUsers();
for (User u: users) {
System.out.println(“User’s name is: ” + user.name;
}
Sophisticated update is also possible.
interface MyQueries extends BaseQuery {
@Update(sql=”update user set department={deparment} where name= {userName}”)
int updateDeparment(String userName, String department);
}
Insertion is also made easy.
Connection c = myDataSource.getConnection();
MyQueries q = c.createQueryObject(MyQueries.class);
DataSet users = q.create();
User user = new User();
user.setUserID(1);
user.setName(“Joe”);
user.setDeparment(“Accounting”);
users.insert(user);
– You might ask why this is relevant to *type safety*. The reason behind this is that the DataSet is actually a subclass of List and it is a parameterized type. In other words, DataSet supports generics. And type erros are subjected to be detected early in the development stages if the type is parameterized.
Leave a Reply