Wednesday, February 18, 2009

JNDI

Setting up a Connection Pool


Database Connection Pooling (DBCP) libraries


Java Naming and Directory Interface (JNDI)

http://java.sun.com/products/jndi/

The Java Naming and Directory Interface (JNDI) is part of the Java platform, providing applications based on Java technology with a unified interface to multiple naming and directory services. You can build powerful and portable directory-enabled applications using this industry standard. » Read More
JNDI and Java EE Technologies
JNDI works in concert with other technologies in the Java Platform, Enterprise Edition (Java EE) to organize and locate components in a distributed computing environment.


commuincation between the server and database is to set up
a database connection pool


database connection pool


creating a new connection for each client request can be very time consuming,
especially for applciatoins that continously receive a large number of request.

tom remedy this..


numerous connections are created and maintaned in a connection tool.

Any incoming requests that requires access to the application's data layer use
an already-created connection from the pool.

Likewise,when a requet is completed, the connection is not close, but return
to the pool.



1. Setting up a JNDI Datasource
2. Referencing the Datasource from the Application
3. Adding the Database Driver's JAR File to the Server



Setting up a JNDI Database

both GlassFish and Tomcat contain Database connection Pooling (DBCP)libraries that proved connction pooling functionality in a way that is transparent toyou as d

developer. In either case, you need to configure a JNDI Datasource for the serverr

that creates an interface withch your applcation ca use for connection pooling
Depending on whether you are using GlassFish or Tomcat,



Any incoming requests that require access to the application's data layer use an already-created connection from the pool.





Tomcat

Configure a JNDI Datasource in Tomcat by adding a declaration for your resource to the application's context.xml file. This is the application's context container, which enables you to specify application meta-data necessary for the server in order to deploy and run the application. There are various locations where you can specify context elements, such as your server's global $CATALINA_HOME/conf/context.xml file. By adding resource declarations to your application's context.xml file however, you limit the resource to that application, and do not need to configure anything within the server itself. For more information, see the Apache Tomcat Configuration Reference.



configure a JNDI Datasource in tomcat by adding a declaration for your
resource to the application's extext.xml


context container.

enable::

specify application meta-data necessary for the sever in order to deploy and run applcation.


From the Projects window, open the application's context container in the Source Editor by double-clicking the Web Pages > META-INF > context.xml file.



Web Pages > META-INF > context.xml file.

Web Pages > META-INF > context.xml file.

Web Pages > META-INF > context.xml file.




Add the following tags (changes below in bold) as a declaration for the JNDI resource:




maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyNewDatabase"/>







maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyNewDatabase"/>








maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyNewDatabase"/>

No comments:

Post a Comment