DEV Community

Cover image for How to handle Database in Spring Boot

Posted on

How to handle Database in Spring Boot

Core data for Spring Boot with Database. Please you may use more source in there link.

This provides Database implementation in the Spring Boot. Especially, we'll briefly inform here concept of Spring, Spring Boot, JDBC, JPA, H2 and result of our experience project(there is link using github).


The Spring Framework is an application framework and inversion of control container for the Java platform. Spring is HA (high avilability).
Spring Boot

Most Spring Boot applications need minimal Spring configuration. Features. Create stand-alone Spring applications


JPA (The Java Presistence API) = This module deals with enhanced support for JPA based data access layers.Indeed, the JPA is set of the rules to interfaces.

  • JPA follows Object-Relation Mapping (ORM). It is a set of interfaces. It also provides a runtime EntityManager API for processing queries and transactions on the objects against the database. It uses a platform-independent object-oriented query language JPQL (Java Persistent Query Language). Why should we use JPA? JPA is simpler, cleaner, and less labor-intensive than JDBC, SQL, and hand-written mapping. JPA is suitable for non-performance oriented complex applications.

API (Application programming interface) is a document that contains a description of all the features of a product or software. It represents classes and interfaces that software programs can follow to communicate with each other. An API can be created for applications, libraries, operating systems, etc.

JPA Implementations JPA is an open-source API. There is various enterprises vendor such as Eclipse, RedHat, Oracle, etc. that provides new products by adding the JPA in them. There are some popular JPA implementations frameworks such as Hibernate, EclipseLink, DataNucleus, etc. It is also known as Object-Relation Mapping (ORM) tool.


Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database.
Architecture of the Project Implementation.
Alt Text


  • H2 is a relational database management system written in Java. It can be embedded in Java applications or run in client-server mode.

Alt Text

Spring Boot + JPA + Hibernate + MySQL|Oracle

Real project configuration. Source.

Create a Maven Project
You may use your tool(Eclipse, IntelliJ Idea, etc.), this example we used IntelliJ then create a new Maven project and name it SpringJDBC.

At the end of this tutorial, we’ll get the following project structure:
Alt Text


  • Configuration DB
    Alt Text

  • Repositories
    We define our repositories' interfaces under spring.jdbc.dao. Each repository extends Spring CrudRepository, which provides a default implementation for the basic find, save, and delete methods — so we don’t care about defining implementation classes for them.

Top comments (0)