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

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

Resources and JNDI Naming

DataSource Objects and Connection Pools

Resource Injection

Field-Based Injection

Method-Based Injection

Class-Based Injection

Declaring Multiple Resources

Theconfirmer Example Application

Running theconfirmer Example Application

Creating a Mail Session

Building, Packaging, and Deployingconfirmer in NetBeans IDE

Building, Packaging, and Deployingconfirmer Using Ant

Running theconfirmer Client in NetBeans IDE

Running theconfirmer Client Using Ant

Further Information about Resources

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

DataSource Objects and Connection Pools

To store, organize, and retrieve data, most applications use a relational database. JavaEE 5 components may access relational databases through the JDBC API. For information onthis API, seehttp://www.oracle.com/technetwork/java/javase/tech/index-jsp-136101.html.

In the JDBC API, databases are accessed by usingDataSource objects. ADataSource hasa set of properties that identify and describe the real world data sourcethat it represents. These properties include information such as the location of thedatabase server, the name of the database, the network protocol to use tocommunicate with the server, and so on. In the Application Server, a datasource is called a JDBC resource.

Applications access a data source using a connection, and aDataSource objectcan be thought of as a factory for connections to the particular datasource that theDataSource instance represents. In a basicDataSource implementation, a call tothegetConnection method returns a connection object that is a physical connection tothe data source.

If aDataSource object is registered with a JNDI naming service, an applicationcan use the JNDI API to access thatDataSource object, which canthen be used to connect to the data source it represents.

DataSource objects that implement connection pooling also produce a connection to the particulardata source that theDataSource class represents. The connection object that thegetConnectionmethod returns is a handle to aPooledConnection object rather than being a physicalconnection. An application uses the connection object in the same way that ituses a connection. Connection pooling has no effect on application code except thata pooled connection, like all connections, should always be explicitly closed. When anapplication closes a connection that is pooled, the connection is returned to apool of reusable connections. The next timegetConnection is called, a handle toone of these pooled connections will be returned if one is available. Because connectionpooling avoids creating a new physical connection every time one is requested, applicationscan run significantly faster.

A JDBC connection pool is a group of reusable connections for aparticular database. Because creating each new physical connection is time consuming, the server maintainsa pool of available connections to increase performance. When an application requests aconnection, it obtains one from the pool. When an application closes a connection,the connection is returned to the pool.

Applications that use the Persistence API specify theDataSource object they areusing in thejta-data-source element of thepersistence.xml file.

<jta-data-source>jdbc/MyOrderDB</jta-data-source>

This is typically the only reference to a JDBC object for apersistence unit. The application code does not refer to any JDBC objects. Formore details, seePersistence Units.

PreviousContentsNext

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


[8]ページ先頭

©2009-2025 Movatter.jp