Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CREATING AND SETTING UP A MYSQL DATASOURCE IN PAYARA

1. Unzip the file containing the JDBC Driver


• Make sure the version of the driver matches the version of
your MySQL BD

2. Copy the file mysql-connector-java-x.x.x-bin.jar in the folder of the


Payara installation:
• /payara/glassfish/lib
• /payara/glassfish/domains/nombredominio/lib

3. Start the Payara from Eclipse


4. From the server Windows right-click on the Glassfish server and
open the administrator console
• Use the Chrome browser if necessary to access the console
(http://localhost:4848/)
• User: admin
• Password: admin
5. From the main menu “Common Task” expand the menu
“Resources” and click on the entry “JDBC”
6. Click on ‘Connection Pools’ to display the page of the connection
pools.

7. Click on “New”
8. Type a name for the new JDBC connection pool. Select javax.sql.
DataSource as ‘Resource Type’ and MySQL as ‘Database vendor’.
9. In the field ‘DataSource ClassName’ write as an alternative to the
default displayed by default:
com.mysql.cj.jdbc.MysqlConnectionPoolDataSource.

10. In “Properties” add the following ones. Remember to change the


password and the name of the database to match yours in the
properties “password”, “url” and “databaseName”, respectively

11.Click “Finish” to go back to the connection pools page


12.Click on the pool you just created to go to the page ‘Edit Connection
Pool’.
13.Click on “Ping” to check that the connection has been set up
correctly

14.Now go to the menu “JDBC Resources” in the “JDBC” menu


15.Click on “New”
16.Type the JNDI name for the new DataSource. In the field “Pool
Name” select the pool you just created

17.Click OK to finish

Now you can obtain a connection with the DataSource using this code
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
. . .
public Class . . .
@Resource (mappedName=”TIWDS”)
DataSource ds;

You might also like