Glassfish Connection Pool for MySQL

Last modified by Ken McWilliams on 2012/03/15 21:23

Using Glassfish 3.1.2.1 and MySQL actually MariaDB ver 5.3.2 but it will not make a difference in configuration.

Install the MySQL Driver for Glassfish

  1. Download the latest mysql java driver (at time of writing 5.1.18): http://dev.mysql.com/downloads/connector/j/
  2. Extract the contents and locate mysql-connector-java-x.x.x-bin.jar (where x.x.x is the current version)
  3. Copy this file to  GLASSFISH_INSTALL_DIR/bin on my system this is: /home/ken/glassfish-3.1.2/glassfish/lib

Configuration Starting in Netbeans 7.1.1

  1. Click on the Services tab -> Servers -> Right click "GlassFish Server 3.1.2.1" and select "Start" (NOTE: If the server was already running when the mysql connector jar was moved into the lib folder, restart glassfish now)
  2. Right click "GlassFish Server 3.1.2.1" and select "View Domain Admin Console"

Glassfish domain console

Resources -> JDBC -> JDBC Connection Pools -> Click "New..."

Enter the following values
Pool Name = Name for your pool (ie: Gallery)
Resource Type =   javax.sql.ConnectionPoolDataSource
Database Driver Vendor = MySql
Introspect = Leave this unchecked

Click Next.

The defaults should be fine to start with, however we need to add some additional properties to make the connection.

Scroll down the the "Additional Properties" table.

Locate and set the following properties:

User = name of mysql user who will access the database (ie: root)
DatabaseName = name of mysql database/schema (ie: gallery)
Password = password mysql requires for the above user (ie: password)
URL = jdbc:mysql://localhost:3306/database_name (ie: jdbc:mysql://:3306/gallery)
Url = jdbc:mysql://localhost:3306/database_name (Yes we really need to enter this string twice)
ServerName = localhost

Click Finish

Under the General tab, test the connection with "Ping" if we see "Ping Succeeded" we are good so far, if not check values
we just entered.

Create a JNDI name for the connection pool

Resources -> JDBC -> JDBC Resources -> click "New..."

JNDI Name = (what you want to call the pool, ie: jdbc/gallery )
Pool Name = (Select the pool we just created from the drop down)
Description = (Optional, ie: "Connection to the Gallery Database")

Click "OK" and you are ready to use the connection pool via the JNDI name in your application via JPA/Spring.