Skip to content

H2 Database Quick Start Guide

๐Ÿš€ Getting Started

Run the Application

./gradlew bootRun

That's it! The application starts with H2 database automatically initialized with sample data.


๐Ÿ—„๏ธ Access H2 Console

URL: http://localhost:8080/h2-console

Login Credentials: - JDBC URL: jdbc:h2:mem:sampledb - Username: sa - Password: (leave empty)

Click Connect to access the database console.


๐Ÿ“Š Sample Data Available

Products Table (10 items)

  • Scooby Doo series toys (5 items)
  • Cars series toys (5 items)

Insurance Members Table (1 member)

  • John Deer with 3 policies and 6 plans

๐Ÿ” Useful SQL Queries

View All Products

SELECT * FROM PRODUCTS;

View All Members

SELECT * FROM INSURANCE_MEMBERS;

View Member Policies

SELECT * FROM MEMBER_POLICIES;

View Policy Plans

SELECT * FROM POLICY_PLANS;

Search Products by Name

SELECT * FROM PRODUCTS WHERE NAME LIKE '%scooby%';

๐Ÿงช Run Tests

./gradlew test

All repository tests now pass automatically!


๐Ÿณ Docker Deployment

# Build and start
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

๐Ÿ“ Key Features

โœ… No Setup Required - Database is embedded
โœ… Auto-Initialized - Sample data loaded on startup
โœ… Web Console - Inspect data via browser
โœ… Fast Tests - No external dependencies
โœ… Self-Contained - Perfect for demos


๐Ÿ”— API Endpoints

  • Swagger UI: http://localhost:8080/swagger-ui.html
  • Health Check: http://localhost:8080/actuator/health
  • H2 Console: http://localhost:8080/h2-console

๐Ÿ“š More Information

See H2_MIGRATION.md for complete migration details.