16.10.2015 Views

Getting Started with WebSphere Application Server

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4 – Working <strong>with</strong> databases 77<br />

Figure 4.15 – Generated project layout<br />

Because you chose IBM WASCE v2.1 as the target runtime, a Community Edition<br />

configuration file geronimo-web.xml will be created in the WEB-INF folder. This<br />

folder will be used for the Web project to define the Web context as well as some<br />

resource references in the later sections.<br />

4.3.2 Create a JSP and configure the data source reference<br />

In a Java EE programming environment, to access data in a database you normally need<br />

to write code that performs the following:<br />

1. Initialize a JNDI naming context and look up the JDBC data source<br />

2. Get the database connection, execute SQL statements, and present the data<br />

3. Close the database connection<br />

Let’s create a JSP file to implement the database access logic:<br />

1. In Eclipse, right click on the WebContent folder, then New -> JSP to create a JSP file<br />

as shown in Figure 4.16.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!