8.6. EJB and JDBC example
The JdbcTest EJB demonstrates the JDBC API features described in this chapter, and simple usage of JDBC in an EJB. This is a stateful session EJB, exposing two methods to clients: executeQuery(), which executes the supplied SQL query and returns the results as a printable text string, and getMetaData(), which generates a text string containing some general information about the database. The implementation class is shown in Listing 8.2. Note that the database connection is only opened as required, and closed immediately afterwards, following modern practice (see below). The client creates this EJB by passing the JNDI name of a DataSource to the create() method on the home interface (Listing 8.3). The remote interface ...
Get Applied Enterprise JavaBeans™ Technology now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.