Connecting Your Java Application to a MySQL Database
Every Systron Java hosting plan comes with a MySQL database allocation. Follow these steps to configure your database settings and connect it using standard Java tools.
Step 1: Create the Database Credentials
- Log in to your control panel and click on Databases in the menu sidebar.
- Click Add Database.
- Type in a database name, create a new database user, and choose a secure password. Note down these three values.
- Keep the database host target as
localhostor127.0.0.1since the database resides on the same physical system.
Step 2: Add Your Database Driver
Your application requires a database driver library to talk to MySQL. Ensure the MySQL Connector/J dependency is included in your build configurations:
- For Maven: Add the
mysql-connector-jartifact group dependency inside yourpom.xmlfile. - For Gradle: Include the implementation runtime parameter for the MySQL connector within your
build.gradlefile. - For Manual Bundles: Ensure the
mysql-connector-java-xxx.jarbinary file is safely dropped inside your application'sWEB-INF/lib/directory before you package the final layout.
Step 3: Standard JDBC Connection Properties
You can use standard JDBC parameters to establish your database manager pool. We strongly recommend loading these configurations through external configuration properties files or system variables rather than hardcoding them into compiling classes:
# Example database properties configuration db.url=jdbc:mysql://localhost:3306/YOUR_DATABASE_NAME?useSSL=false&serverTimezone=UTC db.username=YOUR_DATABASE_USER db.password=YOUR_DATABASE_PASSWORD db.driver=com.mysql.cj.jdbc.Driver
After saving your configuration files and redeploying your archive, restart the application backend from your control panel dashboard to establish the data pipeline.