DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones Build AI Agents That Are Ready for Production
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
Build AI Agents That Are Ready for Production

"Platform Engineering & DevOps" Trend Report is now LIVE! Learn how internal platforms help developers ship faster with less friction

Join this live webinar to learn safer rollout techniques for schema changes, index testing, and database migrations.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Spring Boot: How To Use Java Persistence Query Language (JPQL)
  • How To Build Web Service Using Spring Boot 2.x
  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis

Trending

  • Metal and Skins
  • Advanced Error Handling and Retry Patterns in Enterprise REST Integrations
  • Stop Choosing Sides: An Engineering Leader's Framework for Build, Buy, and Hybrid AI Agents in 2026
  • Your AI Is Not Failing, Your Context Is
  1. DZone
  2. Data Engineering
  3. Databases
  4. Connecting Spring Boot With MySQL and Oracle Databases

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.

By 
Ranga Karanam user avatar
Ranga Karanam
·
Jan. 18, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
78.4K Views

Join the DZone community and get the full member experience.

Join 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.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

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

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.1</version>
</dependency>

Step 2 - Remove H2 Dependency From pom.xml

Or at least make its scope as test

<!--
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>test</scope>
</dependency>
-->

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.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/todo_example
spring.datasource.username=todouser
spring.datasource.password=YOUR_PASSWORD

spring.jpa.hibernate.ddl-auto

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!

Database Spring Framework Spring Boot MySQL

Published at DZone with permission of Ranga Karanam. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Spring Boot: How To Use Java Persistence Query Language (JPQL)
  • How To Build Web Service Using Spring Boot 2.x
  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook