๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โŒจ๐Ÿ–ฑ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/๐Ÿ“ ํ”„๋กœ์ ํŠธ

[2] Spring์— h2 ์„ค์ • (IntelliJ)

by rrUro 2023. 9. 17.

1. H2 ์„ค์น˜

https://www.h2database.com/html/main.html

 

H2 Database Engine

H2 Database Engine Welcome to H2, the Java SQL database. The main features of H2 are: Very fast, open source, JDBC API Embedded and server modes; in-memory databases Browser based Console application Small footprint: around 2.5 MB jar file size     Supp

www.h2database.com

 

2. . H2์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ

h2\bin ๋ฐ‘์— h2 ๋ฐฐ์น˜ํŒŒ์ผ ์‹คํ–‰

์˜คํ”ˆ๋œ ์ฝ˜์†”์— ์„ค์ • ํ›„ connect ํด๋ฆญ

  • JDBC URL : jdbc:h2:~/testDB
  • User Name : rruro

C:\Users\์‚ฌ์šฉ์žid ๋ฐ‘์— study.mv ํŒŒ์ผ ์ƒ์„ฑ ํ™•์ธ ํ›„ ์—ฐ๊ฒฐ ๋Š๊ธฐ

โ€ป ์—ฐ๊ฒฐ ์•ˆ ๋Š๊ณ  localhost๋กœ ์ ‘์†ํ•˜๋ฉด ์—๋Ÿฌ๋œธ

Database may be already in use: . Possible solutions: close all other connection(s); use the server mode [90020-214] 90020/90020 

 

3. build.gradle - dependencies ์ถ”๊ฐ€

runtimeOnly 'com.h2database:h2'

 

4. application.properties ํŒŒ์ผ ๋ณ€๊ฒฝ

ํ™•์žฅ์ž๋ช…๋งŒ ๋ฐ”๊ฟ”์„œ application.yml ํŒŒ์ผ๋กœ ๋ณ€๊ฒฝ

 

5. application.yml ํŒŒ์ผ ์„ค์ •

spring:

  h2:
    console:
      enabled: true
      path: /h2-console

  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:~/testDB
    username: rruro
    password:

 

6. Gradle ์ƒˆ๋กœ๊ณ ์นจ

 

7. ํ”„๋กœ์ ํŠธ ์‹คํ–‰

 

8. ์ ‘์†

localhost:8080/h2-console ์— ์ ‘์† (study-h2๋Š” application.yml์—์„œ ์„ค์ •ํ•œ h2 path ์ž…๋ ฅ)