Wiki source code of Glassfish Connection Pool for MySQL
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | Using Glassfish 3.1.2.1 and MySQL actually MariaDB ver 5.3.2 but it will not make a difference in configuration.\\ | ||
2 | |||
3 | == Install the MySQL Driver for Glassfish == | ||
4 | |||
5 | 1. Download the latest mysql java driver (at time of writing 5.1.18): http:~/~/dev.mysql.com/downloads/connector/j/ | ||
6 | 1. Extract the contents and locate mysql-connector-java-x.x.x-bin.jar (where x.x.x is the current version) | ||
7 | 1. Copy this file to GLASSFISH_INSTALL_DIR/bin on my system this is: /home/ken/glassfish-3.1.2/glassfish/lib\\ | ||
8 | |||
9 | == | ||
10 | Configuration Starting in Netbeans 7.1.1 == | ||
11 | |||
12 | 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) | ||
13 | 1. Right click "GlassFish Server 3.1.2.1" and select "View Domain Admin Console"\\ | ||
14 | |||
15 | == | ||
16 | Glassfish domain console == | ||
17 | |||
18 | Resources -> JDBC -> JDBC Connection Pools -> Click "New..." | ||
19 | \\Enter the following values | ||
20 | **Pool Name** = Name for your pool (ie: Gallery) | ||
21 | **Resource Type** = javax.sql.ConnectionPoolDataSource | ||
22 | **Database Driver Vendor** = MySql | ||
23 | **Introspect** = Leave this unchecked | ||
24 | \\Click **Next**. | ||
25 | \\The defaults should be fine to start with, however we need to add some additional properties to make the connection. | ||
26 | \\Scroll down the the "Additional Properties" table. | ||
27 | \\Locate and set the following properties: | ||
28 | \\**User** = name of mysql user who will access the database (ie: root) | ||
29 | **DatabaseName** = name of mysql database/schema (ie: gallery) | ||
30 | **Password** = password mysql requires for the above user (ie: password) | ||
31 | **URL** = jdbc:mysql:~/~/localhost:3306/database_name (ie: jdbc:mysql:~/~/:3306/gallery) | ||
32 | **Url** = jdbc:mysql:~/~/localhost:3306/database_name (Yes we really need to enter this string twice) | ||
33 | **ServerName** = localhost | ||
34 | \\Click Finish | ||
35 | \\Under the General tab, test the connection with "Ping" if we see "Ping Succeeded" we are good so far, if not check values | ||
36 | we just entered.\\ | ||
37 | |||
38 | === Create a JNDI name for the connection pool === | ||
39 | |||
40 | === === | ||
41 | |||
42 | Resources -> JDBC -> JDBC Resources -> click "New..." | ||
43 | \\**JNDI Name** = (what you want to call the pool, ie: jdbc/gallery ) | ||
44 | **Pool Name** = (Select the pool we just created from the drop down) | ||
45 | **Description** = (Optional, ie: "Connection to the Gallery Database") | ||
46 | \\Click "OK" and you are ready to use the connection pool via the JNDI name in your application via JPA/Spring. |