Database "C:/Users/kai/test" not found, either pre-create it or allow remote database creation [90149-214] 90149/90149
원인
H2 Database를 처음 연동할 시 주로 볼 수 있는 에러이다.
주로 연동 이후 웹 H2 Console로 연결 테스트를 진행할 때 볼 수 있는 에러인데, 해당 에러의 경우 보안 정책상 데이터베이스를 생성할 수 없어서 데이터베이스를 별도로 생성해 주거나, 원격 데이터베이스 생성을 허용해야 한다.
해결방법
보안상으로 추천되지 않으니, 직접 데이터베이스를 생성하려면 에러 메시지 상의 위치 C:/User/kai [사용자명]/test [데이터베이스명]로 이동하여서 test.mv.db 파일을 생성하면 해당 문제를 해결할 수 있다. test의 경우 데이터베이스명이므로, jdbc:h2:~/errortest 같은 경우에는 errortest.mb.db로 데이터베이스 파일을 생성하여야 한다.
데이터베이스를 생성한 뒤, 다시 Test Connection을 실행하면 아래와 같은 성공 메시지를 볼 수 있다.
// DB (2개중 택 1)
spring.datasource.url= jdbc:h2:~/test // 임베디드 모드 (인메모리)
spring.datasource.url= jdbc:h2:tcp://localhost/~/test // 서버 모드
spring.datasource.driver-class-name= org.h2.Driver // 데이터 베이스 설정
spring.datasource.username= sa // 접속 시 사용할 유저명
spring.datasource.password= // 접속 시 사용할 패스워드
// 데이터 설정
spring.sql.init.mode= always // 데이터베이스 초기화 (기본 never)
spring.sql.init.schema-locations= classpath:db/schema.sql // 첫 실행시 실행 할 DDL 데이터
spring.sql.init.data-locations= classpath:db/data.sql // 첫 실행시 실행 할 DML 명령
// H2 DB 콘솔
spring.h2.console.enabled= true // 콘솔 사용 여부
spring.h2.console.path= /h2-console // 콘솔 주소
브라우저 콘솔 접속
spring.h2.console.path로 설정한 위치로 접속하면 해당 콘솔을 확인하여, 접속할 수 있다.
접속하면 schema.sql, data.sql 에서 설정한 바와 같이 미리 테이블과 데이터가 입력되고, SQL문을 사용하여 데이터를 확인 가능하다.