Derby Embedded Database for Spring Boot

In this post, We will see how we can use Apache Derby embedded database with Spring Boot applications with an example.


Apache Derby is a pure java implementation of a relational database. Also, it complies to JDBC and RDBMS standards. For this reason, we can easily embed Derby into applications.

Derby Dependencies

To include derby into the project, All you have to do is to add the Derby and JPA Starter dependencies from Spring Boot.


Notice that we did not specify any versions as spring boot takes care of all of its dependencies through its spring-boot-dependencies BOM.

Spring Boot configuration

Spring Boot takes care of most of the configuration. For instance, it generates an memory based derby connection string, an user with name “sa” and an empty password. However, You can override this using the following properties.


You can run the database in directory mode so that you can store the data in filesystem. This way, you can persist the data over application restarts.

For example, The following setting would setup a database directory in the application working directory.

Derby database files created by Spring Boot

Unlike h2 database, Spring Boot doesn’t support any web based console for Derby.

Initializing Schema

All embedded databases would require initializing Schema. This is because the embedded databases are not persistent and would lose data on restart. To achieve this, Spring Boot expects a schema.sql and data.sql file in classpath.

If you have different file names, you can use the following properties.


You can also disable initialization by adjusting the mode.


Let’s test out out setup. Here is a sample database entity and the data to be loaded for it.

public class UserEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String firstName;
    private String lastName;
insert into user_entity (id,first_name,last_name) values (1,'Homer','Simpson');
insert into user_entity (id,first_name,last_name) values (2,'Bart','Simpson');
insert into user_entity (id,first_name,last_name) values (3,'Lisa','Simpson');

And here is the API call for looking up the initialized data.

public List<UserEntity> getUsers() {
return userRepository.findAll();
Spring Boot derby demo

When starting the application, you may see the following warning.

Caused by: org.apache.derby.iapi.error.StandardException: ‘DROP TABLE’ cannot be performed on ‘USER_ENTITY’ because it does not exist.

It is because the derby instance is refreshed every time and it doesn’t have any table to be dropped. However, spring boot thinks it needs to clear the tables. As this is just a warning, you can ignore this stack trace.


To summarize, We learned how to include derby into a Spring boot application. The example for this guide can be found in this github repository.

Leave a Comment