Error

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

luminous13 2022. 9. 20. 23:58

상황

h2 웹 콘솔에서 연결하기를 눌렀을 때 뜬 오류

 

문제

프로젝트를 실행할 때마다  H2 DB 연결을 위한 URL을 랜덤하게 생성하여 주지만 그 주소가 아니라 jdbc:h2:mem:test라는 URL로 접속하는게 문제였다.

실제로 프로젝트를 실행하면 접속할 JDBC URL을 주고 있는것을 확인할 수 있었다.

이 주소를 입력하니 실제로 H2 DB에 접속할 수 있었다!

 

하지만 실행할 때 매번 주소가 바뀌기 때문에 테스트할 때 번거롭다는 불편한 상황을 마주치게 된다.

 

해결

application.properties 파일에 아래와 같이 JDBC URL을 명시적으로 작성하면 앞으로 그 URL로 변경없이 접속할 수 있다.

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

참고

https://stackoverflow.com/questions/63864373/what-is-the-default-name-of-embedded-h2-database-in-spring-boot

 

What is the default name of embedded H2 database in Spring Boot?

As I've read the default name of the embedded H2 database in Spring Boot should be testdb, but if I try to connect to with the H2 Console, I get the following error: Database "mem:testdb"...

stackoverflow.com

https://stackoverflow.com/questions/61865206/springboot-2-3-0-while-connecting-to-h2-database