Apache Geronimo jndi Naming and Java Resource Connection pool, part 1th: Data source Connection

Source: Internet
Author: User
Tags one table

Use JNDI access to connection pools for data sources, Java messaging services, mail sessions, and URL connections

Understanding JNDI

JNDI is an application programming interface (API) or library that provides an application with methods to associate names with objects and to find objects in the directory based on the name of the object. This article is the first part of a series of tutorials that will give you an idea of how Geronimo, Jndi, and data source connection pools are interconnected, how to build data source connections, and how to leverage JNDI in a simple Geronimo application called the Customer Service Utility) to access the connection.

A data source is an object or factory that is used to generate a connection to an actual data source (typically a database) within an application. In Java Platform, Enterprise Edition (Java EE), this data source refers to a database connection pool, a set of readily available database connections. The reason for creating a data source or database pool is that it can improve application performance, because even opening a connection can be very CPU intensive.

The Customer Service utility (available in the Downloads section of this article) is a simple WEB application that allows basic customer information to be saved to the database. You will use the Apache Ant 1.6.5 and Java 1.4.2_10 to build the utility, deploy it to Geronimo 1.1 with Tomcat, and use the Apache Derby database that is bound to Geronimo. The next section describes how to use the Geronimo console to create this database and data source.

Set up Geronimo

The Geronimo console can manage Java EE components in a user-friendly manner. When Geronimo is started, you can access the Geronimo console located in Http://localhost:8080/console. The default user name and password are system and manager respectively.

Start Step:

Click the DB Manager link located in the lower-left corner of the Console navigation panel. This link represents the Derby database manager.

Create the customer service database by typing customerservicedatabase in the Create DB field, and then click the Create button.

Create a database table by selecting Customerservicedatabase in the Use DB pull-down menu.

Then paste the contents of the SQL script shown in Listing 1 into the table and click the Run SQL button. Please note that the SQL script in Listing 1 is included in the source code.

Listing 1. SQL scripts

CustomerService-Part1.sql
create table customers (
   customerid varchar(10) primary key,
   fullname varchar(30),
   emailaddress varchar(30),
   interests varchar(100)
);
insert into customers values ('A100','John Doe10','Doe10@work.com','Java,Open Source,
Computer Graphics');
insert into customers values ('b100','Jane Doe20','Doe20@home.net','Budget Travel, New
Zealand, Martial Arts');

The customer service database should now be created in Derby. The database has only one table Customers, and there are only two entries in the table. Figure 1 shows the normally initialized table that appears after clicking the Application link, and then clicking the View Contents link.

Figure 1. Customer Service Database after initialization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.