Over a million developers have joined DZone.

Connecting Spring Boot With MySQL and Oracle Databases

DZone's Guide to

Connecting Spring Boot With MySQL and Oracle Databases

In this post, we will go walk through, step-by-step, how to integrate a Spring Boot application MySQL and Oracle databases.

· Integration Zone ·
Free Resource

WSO2 is the only open source vendor to be named a leader in The Forrester Wave™: API Management Solutions, Q4 2018 Report. Download the report now or try out our product for free.

This guide will help you understand how to connect Spring Boot with databases like MySQL and Oracle.

You Will Learn

  • How to connect a Spring Boot, JPA application with MySQL and Oracle.
  • What should you configure in application.properties.
  • How to set up the database schema.

Updating the Spring Boot Project Step by Step

Let's look at the 5 steps involved in connecting a Spring Boot application to a database.

You can use the example we created earlier for connecting to H2 in a memory database as the starting point for this article.

Step 1 - Add a Dependency for Your Database Connector to pom.xml

An example for a MySQL database is shown below.


If you would want to connect to an Oracle database, you can use a dependency similar to the one shown below.


Step 2 - Remove H2 Dependency From pom.xml

Or at least make its scope as test


Step 3 - Setup Your MySQL Database

We would need to set up a database with a schema and the tables.

For an example, check out my GitHub repo.

Step 4 - Configure Your Connection to Your Database

Configure application.properties to connect to your database.

An example for a MySQL database is shown below:



Spring Boot chooses a default value for this based on whether you are connecting to an embedded database or not.

  • Embedded Databases - default create-drop
  • Other Databases - default none

Here is a quick guide to all the options

  • none: No action will be performed.
  • create-only: Database creation will be generated from entities.
  • drop: Database dropping will be generated from entities.
  • create: Database dropping will be generated followed by database creation.
  • validate: Validate entities with the database schema.
  • update: Update the database schema based on the entities.

Step 5 - Restart and You Are Ready!

Read the WSO2 Methodology for Agility to see how you can transform your integration projects from semi-agile to a scalable continuous agile approach.

spring boot ,integration ,database integration

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}