A simple Spring Boot project that demonstrates how to connect to a SQLite database and display data on a web page. Intended as a beginner tutorial for students learning web development.
- Java 17 or later — Download JDK
- Git — to clone the repository
No need to install Gradle separately. The project includes the Gradle wrapper (
gradlew).
-
Clone the repository and navigate into the project folder:
git clone <repository-url> cd spring-boot-project
-
Build the project:
./gradlew build -x test -
Run the application:
./gradlew bootRun
-
Open your browser and go to
http://localhost:8080
If you see this error when running ./gradlew bootRun:
Web server failed to start. Port 8080 was already in use.
It means a previous instance of the application is still running. To fix it, find and stop that process:
On macOS / Linux:
fuser -k 8080/tcpOn Windows:
netstat -ano | findstr :8080
taskkill /PID <PID> /FReplace <PID> with the number from the first column. Then run ./gradlew bootRun again.
src/
├── main/
│ ├── java/com/example/demo/
│ │ ├── DemoApplication.java # Entry point
│ │ ├── Student.java # JPA entity
│ │ ├── StudentRepository.java # Spring Data repository
│ │ └── StudentController.java # Web controller
│ └── resources/
│ ├── application.properties # Database configuration
│ └── templates/index.html # Thymeleaf web page
- Spring Boot 3.4.3 — application framework
- Spring Data JPA — database access
- SQLite — lightweight file-based database
- Thymeleaf — server-side HTML templating
Spring Boot normally expects databases like MySQL or PostgreSQL. Connecting to SQLite requires three small additions:
1. Dependencies (build.gradle)
implementation 'org.hibernate.orm:hibernate-community-dialects' // SQLite dialect for Hibernate
runtimeOnly 'org.xerial:sqlite-jdbc:3.45.1.0' // JDBC driver for SQLite2. Configuration (application.properties)
spring.datasource.url=jdbc:sqlite:test.db # path to the SQLite file
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto=update # auto-creates tables on startup3. Entity class (Student.java)
A plain Java class annotated with @Entity is all that is needed. Spring Data JPA maps it to a table in the SQLite file automatically.
@Entity
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
}When the app starts, Hibernate reads the dialect, connects to test.db (creating the file if it does not exist), and creates the student table based on the entity.