Saturday, July 17, 2010

Configure MySQL Connection Pool in Glassfish V3

The MySQL connection pool in GlassFish V3, is actually as easy as it was in V2!

First of all, we need to download from www.mysql.com the latest jdbc driver:

http://dev.mysql.com/downloads/connector/j/5.1.html

Extract the downloaded archive and take the mysql-connector-java-x.x.x-bin.jar from the compressed archive and put it in {glassfish_installation}/glassfish/lib directory and restart glassfish (from {glassfish_installation}/glassfish/bin directory):

asadmin stop-domain domain1
asadmin start-domain domain1

Now we need to navigate to the administrator application:
http://localhost:4848/
 
Open the 'Resources' -> 'JDBC' -> 'Connection Pools' and select 'New'.
Fill in the Connection Pool 'Name' with a suitable name like MySQLPool.
Select 'Resource Type' : 'javax.sql.DataSource'.
Select 'Database Vendor' : 'MySQL'.
Select 'Next'.

At the next page go down at the additional Properties.
Find and edit the following properties :
Fill in property 'User' with the 'Value' : {db_user}
Fill in property 'Password' with the 'Value' : {db_user_pass}
Fill in property 'URL' with the 'Value' :
jdbc:mysql://[host]:[port]/[database name]
Select 'Finish'.

Navigate to Connection Pools and select the pool you just created.
Click Ping to test that it is working. If it is not, it is probably because you have mistyped the connection credentials. Go to 'Additional Properties' tab of the connection pool detail page and correct any errors. Try ping again.

Open the 'Resources' -> 'JDBC' -> 'JDBC Resources' and select 'New.
Fill the JNDI Name like 'jdbc/myconnnection'.
Select from 'Pool Name' combo box the pool we just created.
And select 'OK'.

The Connection Pool is ready!


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

7 comments:

  1. Hi I am having stale connection issue in glassfish. the issue is occuring when no request coming to server for long time (nearly 7/8 hrs).so plz help me how to configure the connection pool

    ReplyDelete
  2. You could try the autoReconnectForPools parameter for the mysql driver at the jdbc url :
    jdbc:mysql://hostname:port/mydb?autoReconnectForPools=true
    Or you could try setting up the reconnect parameters that glassfish provides at the Advanced Tab of the connection pool you have created (at glassfish admin console). You could try "Validate at most once", "Caonnection Validation", "Validation Method".
    I have never come across with this problem in GlassFish so my help is limited.
    Cheers

    ReplyDelete
  3. denis
    Your GOD sent
    your a good teacher
    keep this job up

    ReplyDelete
  4. Thanks a bunch..God bless you!!!

    ReplyDelete
  5. can u tell further process of how to access it in java

    ReplyDelete