By edort on Dec 11, 2009
Java EE 6 has a wide variety of new features that makes enterprise and web application development a lot easier. I covered many of these features in the article Introducing the Java EE 6 Platform. However, one of the areas of improvement in Java EE 6 that I didn't cover in that article is datasource resource definition.
If you've accessed relational databases through the JDBC API, you know all about
DataSource objects. For those of you who aren't familiar with
DataSource objects, they're Java objects that identify and describe real-world data sources such as relational databases. To access a datasource, you need to define a
DataSource object and register it with the Java Naming and Directory Interface (JNDI) naming service. An application can then use the JNDI API to access that
DataSource object, which can then be used to connect to the datasource it represents.
Prior to Java EE 6, you could create a
DataSource object only through vendor-specific mechanisms, such as commands. However, Java EE 6 makes datasource definition more flexible. It introduces a new datasource definition resource that you can declare portably for database connectivity across any Java EE 6-compatible application server. You can declare datasource definitions either through annotations or through the use of deployment descriptors.
Jagadish Ramu, an engineer in the GlassFish Application Server team, has written a very nice Tech Tip that describes this new capability in more detail and shows code examples that demonstrate datasource definition using annotations and deployment descriptors. The tip also includes a sample application that demonstrates the use of these features. See the tip DataSource Resource Definition in Java EE 6.