[Java] Connection with local DB (IntelliJ + SpringBoot)

Connection with DB by IJ + Spring Boot

Select Data Base tab> Data Source> H2

1.png

Data Sources and Drivers

2.png

** Write and execute the schema to be executed on the H2 console **


create table if not exists employee (
  employee_id bigint primary key,
  employee_name varchar(50),
  age int
);

** When executed, tabel is created **


INSERT INTO employee(employee_id,employee_name,age)
VALUES(1,'Harry Potter',11);
INSERT INTO employee(employee_id,employee_name,age)
VALUES(2,'Hermione Granger',11);
INSERT INTO employee(employee_id,employee_name,age)
VALUES(3,'Ron Weasley',12);
INSERT INTO employee(employee_id,employee_name,age)
VALUES(4,'Albus Dumbledore',110);
--When to delete
-- DELETE FROM	EMPLOYEE
-- WHERE	employee_id = 1

3.png

Check if DB is created

DB.png

create data.sql

application.yml


spring:
  datasource:
    url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    username: sa
    password:
    driver-class-name: org.h2.Driver
    schema: classpath:schema.sql
    data: classpath:data.sql

  h2:
    console:
      enabled: true

You can also check it on the h2 console!

4.png

Recommended Posts

[Java] Connection with local DB (IntelliJ + SpringBoot)
Try DB connection with Java
JAVA DB connection method
[Template] MySQL connection with Java
DB connection settings Spring-Boot application.properties
Connect to DB with Java
[PDO → DB connection with docker, PHP]
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
VisualStudioCode + Java + SpringBoot
[spring-boot] Complement application.yml with IntelliJ spring assistant plugin
db connection notes
DB connection method-JDBC
IntelliJ + Docker (APP + DB) + SpringBoot (Maven) environment construction
Show a simple Hello World with SpringBoot + IntelliJ
Java local class
HTTPS connection with Java to the self-signed certificate server
Install java with Homebrew
Change seats with java
Install Java with Ansible
Comfortable download with JAVA
[Java] DB migration (Flyway)
Switch java with direnv
Remote debugging with intellij
[Java] SpringBoot + Doma2 + H2
Download Java with Ansible
[Docker] Connection with MySQL
Supports multi-port with SpringBoot
Let's scrape with Java! !!
Build Java with Wercker
Endian conversion with JAVA
Spring Boot application that specifies DB connection settings with parameters
Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)