[PONITOR] h2 Database, 콘솔

두두·2023년 5월 3일
0

PONITOR

목록 보기
2/6

Api를 배포하기 전에 h2 database에서 잘 동작하는지 확인하려고 한다!

h2 Database

h2란?

자바로 작성된 관계형 데이터베이스 관리 시스템

설치가 필요 없고, 용량이 매우 가볍다는 장점이 있다.
또, 웹용 콘솔 제공하여 개발용 로컬DB로 사용하기 좋다~


build.gradle

아래 코드를 build.gradle에 추가해서 h2 DB를 사용하자!

	implementation 'com.h2database:h2'

h2 Console

h2 console을 사용하자!

application.properties

다음의 코드를 추가하고,

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

http://localhost:8080/h2-console 로 접속하면

다음과 같이 콘솔창을 확인할 수 있다.

그런데 여기서 connect을 누르면,

다음의 오류가 발생한다.

Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-214] 90149/90149 (Help)

에러 메세지를 읽어보면, mem:testdb 데이터베이스가 존재하지 않다고 한다.
그러니 미리 생성을 하면 됨!

즉 ,
application.properties에 다음의 코드를 추가!

spring.datasource.url=jdbc:h2:mem:testdb

그러면 콘솔창이 잘 뜨는 것을 확인할 수 있다!

profile
멋쟁이가 될테야

0개의 댓글