Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This sample is a very simple database access application that uses annotations. For this example we have created a sample BankDB database on the embedded Derby . We have also defined before hand as well as a database connection pool. In this section Although we will not cover be covering in this section how to create a database or a connection pool , however we still provide in the #Attachments section the necessary some SQL sample to generate the required sample database.

...

Code Block
java
java
borderStylesolid
titleExcerpt from ListCustomers.java
...
import javax.annotation.Resource;
...

/**
 * Servlet implementation class for Servlet: ListCustomers
 *
 */
 public class ListCustomers extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	@Resource(name = "jdbc/MyDataSource")
	private DataSource dataSource;
...

With Geronimo the server up and running open access the Geronimo Administration Console with a web browser and click on Plan Creator on the left menu.

Browse to the WebAppJDBCAccessAnnotations.war you just extracted and click on Configure. In the resulting screen you will be configuring the web application identity. You may want to change the default proposed values however, for this example, we will be accepting the defaults. Click Next.

In the following screen, the wizard have identified some WAR references that need to be resolved. The references listed on this screen are specific to this application. The JDBCRef column is showing the resource name defined in ListCustomers.java; see *@Resource(name = "jdbc/MyDataSource") from the left menuthe excerpt above.

As mentioned earlier, for this example we created a database connection pool we called BankDB_Pool. From the JDBC Pools puul-down menu you can now select the appropriate connection pool and click Next.

EJB access
Anchor
ejb
ejb

JMS access
Anchor
jms
jms

...