Using Connector/J with GlassFish
2111
6. You can accept the default settings for General Settings, Pool Settings and Transactions for this
example. Scroll down to Additional Properties.
7. In Additional Properties you will need to ensure the following properties are set:
• ServerName - The server to connect to. For local testing this will be
localhost
.
• User - The user name with which to connect to MySQL.
• Password - The corresponding password for the user.
• DatabaseName - The database to connect to, for example the sample MySQL database
World
.
8. Click Finish to exit the wizard. You will be taken to the JDBC Connection Pools page where all
current connection pools, including the one you just created, will be displayed.
9. In the JDBC Connection Pools frame click on the connection pool you just created. Here you can
review and edit information about the connection pool.
10. To test your connection pool click the Ping button at the top of the frame. A message will be
displayed confirming correct operation or otherwise. If an error message is received recheck the
previous steps, and ensure that MySQL Connector/J has been correctly copied into the previously
specified location.
Now that you have created a connection pool you will also need to create a JDBC Resource (data
source) for use by your application.
Creating a JDBC Resource
Your Java application will usually reference a data source object to establish a connection with the
database. This needs to be created first using the following procedure.
• Using the navigation tree in the Glassfish Administration Console, navigate to Resources, JDBC,
JDBC Resources. A list of resources will be displayed in the JDBC Resources frame.
• Click New. The New JDBC Resource frame will be displayed.
• In the JNDI Name field, enter the JNDI name that will be used to access this resource, for example
enter
jdbc/MySQLDataSource
.
• In the Pool Name field, select a connection pool you want this resource to use from the drop-down
listbox.
• Optionally, you can enter a description into the Description field.
• Additional properties can be added if required.
• Click OK to create the new JDBC resource. The JDBC Resources frame will list all available JDBC
Resources.
20.3.14.1. A Simple JSP Application with Glassfish, Connector/J and MySQL
This section shows how to deploy a simple JSP application on Glassfish, that connects to a MySQL
database.
This example assumes you have already set up a suitable Connection Pool and JDBC Resource, as
explained in the preceding sections. It is also assumed you have a sample database installed, such as
world
.
The main application code,
index.jsp
is presented here:
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...