Wednesday, April 23, 2014

Tutorial Java Glassfish Netbeans MySQL

Configure the connection pool in Glassfish


Copy the MySQL connector jar file into /lib folder
Start Glassfish server (or restart it if it was already running

Once Glassfish is installed you will need to make sure it can access MySQL Connector/J. 

To do this copy the MySQL Connector/J JAR file to the directory GLASSFISH_INSTALL/glassfish/lib

For example, copy mysql-connector-java-5.1.12-bin.jar to C:\glassfishv3\glassfish\lib


Restart the Glassfish Application Server
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!