Movatterモバイル変換


[0]ホーム

URL:


Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

Web Applications

Web Application Life Cycle

Web Modules

Packaging Web Modules

Deploying a WAR File

Setting the Context Root

Deploying a Packaged Web Module

Testing Deployed Web Modules

Listing Deployed Web Modules

Updating Web Modules

Updating a Packaged Web Module

Dynamic Reloading

Undeploying Web Modules

Configuring Web Applications

Mapping URLs to Web Components

Setting the Component Alias

Declaring Welcome Files

Setting Initialization Parameters

Mapping Errors to Error Screens

Declaring Resource References

Declaring a Reference to a Resource

Declaring a Reference to a Web Service

Duke's Bookstore Examples

Accessing Databases from Web Applications

Populating the Example Database

Creating a Data Source in the Application Server

Further Information about Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

10.  JavaServer Faces Technology

11.  Using JavaServer Faces Technology in JSP Pages

12.  Developing with JavaServer Faces Technology

13.  Creating Custom UI Components

14.  Configuring JavaServer Faces Applications

15.  Internationalizing and Localizing Web Applications

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

24.  Introduction to the Java Persistence API

25.  Persistence in the Web Tier

26.  Persistence in the EJB Tier

27.  The Java Persistence Query Language

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web Applications

31.  The Java Message Service API

32.  Java EE Examples Using the JMS API

33.  Transactions

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

The Java EE 5 Tutorial

Java Coffee Cup logo
PreviousContentsNext

Accessing Databases from Web Applications

Data that is shared between web components and is persistent between invocations ofa web application is usually maintained in a database. To maintain a catalogof books, the Duke’s Bookstore examples described in ChaptersChapter 4, Java Servlet Technology throughChapter 15, Internationalizing and Localizing Web Applications usethe Java DB database included with the Application Server.

To access the data in a database, web applications use the newJava Persistence API (seeChapter 24, Introduction to the Java Persistence API). SeeChapter 25, Persistence in the Web Tier to learn how the Duke’s Bookstore applicationsuse this API to access the book data.

To run the Duke’s Bookstore applications, you need to first populate the databasewith the book data and create a data source in the ApplicationServer. The rest of this section explains how to perform these tasks.

Populating the Example Database

When you deploy any of the Duke’s Bookstore applications usingant deploy, the database isautomatically populated at the same time. If you want to populate thedatabase separately from the deploy task or are using NetBeans IDE to deploythe application, follow these steps:

  1. In a terminal window, go to thebooks directory or any one of thebookstore1 throughbookstore6 example directories.

  2. Start the Java DB database server. For instructions, seeStarting and Stopping the Java DB Database Server. You don’t have to do this if you are using NetBeans IDE. It starts the database server automatically.

  3. Typeant create-tables. This task runs a command to read the filetut-install/examples/common/sql/javadb/tutorial.sql and execute the SQL commands contained in the file.

  4. At the end of the processing, you should see the following output:

    ...[sql] 181 of 181 SQL statements executed successfully

When you are runningcreate-tables, don’t worry if you see a message thatan SQL statement failed. This usually happens the first time you run thecommand because it always tries to delete an existing database table first beforeit creates a new one. The first time through, there is no tableyet, of course.

Creating a Data Source in the Application Server

ADataSource object has a set of properties that identify and describe thereal world data source that it represents. These properties include information such asthe location of the database server, the name of the database, the networkprotocol to use to communicate with the server, and so on.

Data sources in the Application Server implement connection pooling. To define the Duke’sBookstore data source, you use the installed Derby connection pool namedDerbyPool.

You create the data source using the Application Server Admin Console, following thisprocedure:

  1. Expand the Resources node.

  2. Expand the JDBC node.

  3. Select the JDBC Resources node.

  4. Click the New... button.

  5. Typejdbc/BookDB in the JNDI Name field.

  6. ChooseDerbyPool for the Pool Name.

  7. Click OK.

PreviousContentsNext

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices


[8]ページ先頭

©2009-2025 Movatter.jp