Skip to content

MySQL connection

Diogo Guedes edited this page Mar 27, 2019 · 2 revisions

To interact with the MySQL database we need an established MySQL connection for the project. To create a connection, we need the MySQL connector dependency and to follow these steps:

  1. Create a new connection

create_connection1_img

  1. Select the MySQL connector/driver

create_connection2_img

  1. Specify:
    • the name of the database to which this connection will be connected (the connection can only be connected to 1 database)
    • the user created earlier
    • test the connection

create_connection3_img

  1. Click Next

create_connection4_img

  1. Give a name to the connection

create_connection5_img

When using Glassfish as the web application server, these configurations are stored in glassfish-resources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool allow-non-component-callers="false" ...>
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="3306"/>
        <property name="databaseName" value="merchfinderdb"/>
        <property name="User" value="im_user"/>
        <property name="Password" value="pass"/>
        <property name="URL" value="jdbc:mysql://localhost:3306/merchfinderdb?zeroDateTimeBehavior=convertToNull"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="java:app/mysql_mf_con" object-type="user" pool-name="mysql_merchfinderdb_im_userPool"/>
</resources>

Clone this wiki locally