Giter VIP home page Giter VIP logo

springboot-with-h2-database's Introduction

SpringBoot-with-H2-Database

Project Setup Documentation - Spring Boot with H2 Database

This documentation provides a step-by-step guide on setting up a Spring Boot project with an H2 in-memory database for managing Employee entities. The project will include REST API endpoints to perform CRUD (Create, Read, Update, Delete) operations on Employee data.

Prerequisites:

  • Java Development Kit (JDK) version 17 or later installed on your system.
  • A text editor or an Integrated Development Environment (IDE) of your choice.
  • Apache Maven (latest version) installed on your system (optional, as some IDEs come with Maven integration).

Configure Application Properties

  1. Locate the application.properties (or application.yml) file in your project's resource folder.
  2. Add the following configuration properties to the file:
    spring.datasource.url=jdbc:h2:mem:testdb
    spring.datasource.driverClassName=org.h2.Driver
    spring.datasource.username=sa
    spring.datasource.password=
    spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
    spring.h2.console.enabled=true
    
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.show_sql=true
    

REST API endpoints:

  • GET /employees: Retrieve a list of all employees.
  • GET /employees/{id}: Retrieve an employee by their ID.
  • POST /employees: Create a new employee.
  • PUT /employees/{id}: Update an existing employee by their ID.
  • DELETE /employees/{id}: Delete an employee by their ID.

Build and Run the Project

  1. Use Maven or your IDE's build functionality to build the project.
  2. Once the build is successful, run the Spring Boot application. The application will start, and the H2 database will be initialized in memory.

Test the API

  1. Use tools like Postman or cURL to test the REST API endpoints.
  2. Perform CRUD operations on Employee data using the API.

Accessing H2 Console

  • If you want to access the H2 database console, go to http://localhost:8080/h2-console (assuming your application is running on the default port 8080).
  • Use the JDBC URL jdbc:h2:mem:testdb, and the username sa (with an empty password) to connect to the H2 console.

springboot-with-h2-database's People

Contributors

vivekgupta96 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.