Java Connect to SQLite using Spring Boot

What You’ll Need

  1. Java JDK 8+ installed
  2. IDE (Eclipse, IntelliJ, etc)

What You’ll Get

A bare bones Spring Boot command line app which connects to a SQLite database using JDBCTemplate.

For the database, we’ll be creating a very simple table of beer names.

Create Spring Boot Project

Go to to create the new project.  Leave all the defaults and add “jdbc api” to the dependency list.

Import Maven Project to Your IDE

Unzip the generated file import it into your IDE as a Maven project.  Once imported, add the following depedency into your pom.xml file for the sqlite jdbc driver:

<!-- -->

Your final file will look similar to the below.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""
		<relativePath /> <!-- lookup parent from repository -->
	<description>Demo project for Spring Boot</description>



		<!-- -->




Add Database URL

In your file (located in src/main/resources of your project), add the following like.  This will create a new SQLite database file named “yourdatabasename_here.db” in the same directory as your Java project.  Spring Boot will also use this to autowire your JDBCTemplate instance.


Create Entity Class

The bare-bones entity class below is used for mapping results of our query.

package com.example.demo;

public class Beer{
	private String name;
	public Beer(String name) { = name;
	public String getName() {
		return name;
	public void setName(String name) { = name;
	public String toString() {
		return "Beer [name=" + name + "]";

Application Class

package com.example.demo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;

public class DemoApplication implements CommandLineRunner {

	//Spring Boot will automagically wire this object using
	private JdbcTemplate jdbcTemplate;

	public static void main(String[] args) {, args);

	public void run(String... args) throws Exception {
		//Create the database table:
		jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS beers(name VARCHAR(100))");
		//Insert a record:
		jdbcTemplate.execute("INSERT INTO beers VALUES ('Stella')");

		//Read records:
		List<Beer> beers = jdbcTemplate.query("SELECT * FROM beers",
				(resultSet, rowNum) -> new Beer(resultSet.getString("name")));
		//Print read records:



Execute the app and you should see the following print out in your IDE’s console:

Beer [name=Stella]