본문 바로가기

Spring

[Spring] Could not extract ResultSet / no database selected 오류 해결

 

Spring 프로젝트에 DB를 연결, yml 및 기본 member entity와 member repository만 작성해서 잘 연결되었는지 Junit test를 통해 테스트하고자 했다.

 

코드에는 이상이 없는데 test()를 돌리면 

org.springframework.dao.DataAccessResourceFailureException: could not extract ResultSet; nested exception is org.hibernate.exception.JDBCConnectionException: could not extract ResultSet 

이러한 로그와 함께 오류가 떴다.

 

알아보니 db table을 찾지 못하고 있는 듯하여 전체 프로젝트 application을 돌려보았다. 

이때에는 돌아는 가지만 warn으로  no database selected 로그가 떴다.

DB 연결을 위해 작성한 yml 파일을 살펴보니 당연하게 default db 스키마에 연결했던 url 부분의 문제였다.

이 프로젝트 같은 경우 여러 DB 스키마가 하나의 RDB에 들어있었기 때문에 어떤 데이터베이스를 사용할지 명칭까지 뒤에 이어서 적어주어야 했다.

 

spring:
  datasource:
    driver-class-name: org.mariadb.jdbc.Driver
    url: jdbc:mariadb://DB의URL/DB명
    username: 유저이름
    password: 패스워드