In this tutorial we will cover step-by-step how to setup plain JDBC with Spring Boot 3 and Maven and MySQL Database.
Step 1: Downloading the Spring Initializr Project
Go to start.spring.io and fill in the following information for to download our JDBC project structure.

Make sure to select Project as Maven and Language as Java, you may choose the latest version of Spring Boot (not Snapshot or Mx versions), for me its 3.0.5
Do select the Packaging as jar and you may choose any version of Java thats available, I am going with the latest thats Java 20.
Once all is set, you can click on, Generate button at the bottom to download the project zip file.
Step 2: Importing the JDBC Project to IDE
- Unzip the project file we downloaded at Step 1.
- Open IntelliJ IDE.
- Go to Menu: File -> New -> Project From Existing Source...
- Now select your project folder and click Open
- Keep clicking next, and "Please select project SDK" choose your JDK (in my case JDK 20)
- Right-click on your project and select Maven -> Download Sources
Extract the zip project and open your IDE (Eclipse, IntelliJ, NetBeans or VSCode) to import the project, we will demonstrate using IDEA IntelliJ.
Step 3: Setting up MySQL Database.
Make sure you have download and installed MySQL Database. We will first create our test database.
Next lets create a simple database table.
Next, lets insert a record.
Finally lets check the record was inserted properly.
We are all set with the MySQL Database for our tutorial!
Step 4: Configuration for MySQL with Spring Boot
Open the applications.properties files in your project that you will find under src -> main -> resources and add the below details.
spring.datasource.url=jdbc:mysql://localhost/jdbctest
spring.datasource.username=root
spring.datasource.password=your-db-password-can-be-blank-by-default
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Next open the pom.xml file add the MySQL connector dependency.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.14</version>
</dependency>
We are all set with the JDBC configuration!
Step 5: Creating our CommandLineRunner Class
Let's first create a Pojo Message,
package org.code2care.springboot.jdbctutorial;
public class Message {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "Message{" +
"message='" + message + '\'' +
'}';
}
}
Now we are all set for the final class that we need, we call it JDBCRunner
package org.code2care.springboot.jdbctutorial;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class JDBCRunner implements CommandLineRunner {
private String query = "Select * from message";
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public void run(String... args) throws Exception {
List<Message> messages = jdbcTemplate.query(query, new BeanPropertyRowMapper<>(Message.class));
System.out.println(messages.get(0).getMessage());
}
}
Step 6: Running your Hello JDBC Project
- Create a Zip file using Java Code programmatically
- Eclipse : A java Runtime Environment (JRE) or Java Development kit (JDK) must be available
- How to Sort a LinkedList in Java
- Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver
- How to declare and initialize Array in Java Programming
- [Fix] java: integer number too large compilation error
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Reading .xls and .xlsx Excel file using Apache POI Java Library
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- How to get Client IP address using Java Code Example
- Truncate table using Java JDBC Example
- Struts 2 : There is no Action mapped for namespace [/] and action name [form] associated with context path [/proj]
- How to get file path in Idea IntelliJ IDE
- Java Generics explained with simple definition and examples
- Java SE 8 Update 301 available with various bug fixes and security improvements
- Java: Collect Stream as ArrayList or LinkedList
- Java JDBC Connection with PostgreSQL Driver Example
- How to check if Java main thread is alive
- How to fix Java nio NoSuchFileException wile reading a file
- Java 8+ get Day of the Week Examples with LocalDateTime, DateTime, ZonalDateTime and Instant classes
- Ways to Convert Integer or int to Long in Java
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Fix] Spring Boot: mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
- Java: The value of the local variable string is not used
- Java JDBC: Insert Java 8 LocalDate and Time using PreparedStatement
- Top 10 emerging breakthrough trending technologies - HowTos
- Google Local Guide Program and Perks of Contributing to Google Maps - Google
- iOS 14 Airpods Connected message everytime when the iPhone is unlocked - Apple
- Convert Map to List in Java 8 using Stream API - Java
- Bash Hello World! Script Tutorial - Bash
- Facebook | Error : Sorry, something went wrong We're working on it and we'll get it fixed as soon as we can - Facebook
- #YouMakeStrayKidsStay STRAY KIDS EVERYWHERE ALL AROUND THE WORLD Trending Hashtag - News
- [fix] command not found curl - cURL
Go to the JdbctutorialApplication file and hit run, you should see "Hello Spring JDBC" printed in your IDE Console.
Have Questions? Post them here!