반응형

에러 메시지

 

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을 실행하면 아래와 같은 성공 메시지를 볼 수 있다.

반응형

'개발새발 > 이슈' 카테고리의 다른 글

Connection NetworkTimeout 에러 (HikariCP)  (2) 2021.06.01
반응형

H2 Database 란?
자바로 작성된 관계형 데이터베이스 관리 시스템이다.

서버 (Server) 모드와 임베디드 (Embedded) 모드의 인메모리 DB를 제공하며, 브라우저 기반의 콘솔 모드를 사용할 수 있기 때문에, 과제형 코딩테스트나 개발 단계의 테스트 DB로써 많이 이용된다.


사용법

우선, 사용할 버전을 확인 후, pom.xml이나 build.gradle에 추가하면 된다.

https://mvnrepository.com/artifact/com.h2database/h2

// Maven - pom.xml
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>2.1.214</version>
    <scope>test</scope>
</dependency>

// Gradle - build.gradle
testImplementation group: 'com.h2database', name: 'h2', version: '2.1.214'

 

application.yml or application.properties 설정

그 뒤엔 본인의 사용환경에 맞게 application을 설정해주면 된다.

// 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문을 사용하여 데이터를 확인 가능하다.

 

 

반응형

+ Recent posts