Friday 19 July 2013

Database Pooling in Glassfish



Database Pooling in Glassfish

 
Requirements
·         Glassfish Server

Download and install Glassfish server from https://glassfish.java.net/downloads/3.1.2.2-final.html

Glassfish provides its Connection Pooling mechanism for resources such as EIS Server, JMS Server and Database Server. Connection Pooling is intended to share server resources among requesting clients. 

Once Glassfish is installed download and copy mysql-connector-java-5.1.18-bin.jar file into Glassfish lib directory.
Open command promt and move to <glassfish_home>/bin directory and execute following commands.

To Start the Default Domain

Run the asadmin start-domain command without an operand:

To Stop the Default Domain

Run the asadmin stop-domain command without an operand:

To Create JDBC Connection Pool


1.      Redirect to http://<server_name>:4848 and if prompted, log in to the Administration Console.



2.      Click the Resources node in the tree on the left.


The Resources page is displayed.



3.      Click on JDBC.


The JDBC is displayed.



4.      Click on JDBC Connection Pool.


The JDBC Connection Pool page is displayed.


   5.      Click the New Button on top of the grid





The New JDBC Connection Pool page is displayed.


Enter the Pool Name, select Resource Type, Database Driver Vendor and click Next.
On next page in Additional Properties Tab enter the properties like User, Password URL etc. Click on Finish Button

   6.      Once JDBC Connection Pool is created Click on Ping to test if the pool is created successfully. If not successful, check all the properties again.
   7.      Now Under JDBC Resources, click on JDBC Resources.




The JDBC Resources page is displayed.



   8.      Click New Button.  In New JDBC Resource page



   9.      New JDBC Resource page is displayed

       10.  Select pool from Pool Name, and give  JNDI name.

Now that we have created our DataSource, we'll configure our hihernate.cfg.xml file to access this Data Source. Open your hihernate.cfg.xml from Resources folder and add following properties inside <session-factory>

<property name="connection.datasource"> Your DSN Name</property>
<property name="connection.driver_class">       com.mysql.jdbc.Driver</property>