Setting up a JDBC connection in Glassfish.
This is one of that kind of things that can be a challenge for beginners but, at last, is really simple, easy and fast to do. Follow these steps.
- Be sure that you Glassfish server is stopped before going on.
- Download MySQL JDBC driver from Mysql.com. You can find it here. JDBC driver is called MySQL Connector/J. At the moment I write this article current version is 5.1.25
- Unzip and extract all files from the file. Locate the jar containing the JDBC driver. Currently this file is called mysql-connector-java-5.1.25-bin.jar and is located at the root of the folder you have just unzipped.
- Copy this jar file to $glassfish_install_folder\glassfish\lib
- Start Glassfish and go to the admin console, usually located at http://localhost:4848
- At left side on your console you will see a tree, and one node called Resources. Open Resources\JDBC\JDBC Connection Pools. Create a connection pool with the following properties:Pool name: MyDatabae
Resource type: java.sql.Driver (you can choose any other but by now is the simplest option).
Database Driver Vendor: MySQL. Click on next. Because you choose database driver vendor MySQL you will have already specified the driver classname (com.mysql.jdbc.Driver).
Initial and Minimum Pool Size Set a zero value on this parameter. You don’t need initially 8 connections to the database in your development machine.Set the next additional properties:URL: jdbc:mysql://localhost:3306/booreg
user: set the user you want to access this database. Notice that all connection will use the same user.
password: write the password of your user. Notice that password is stored unencrypted.You should see your screen like similar to this two images: