~/tech-blog/posts/spring-intro-h2 — zsh

H2 데이터베이스 설치와 연동

H2 설치

다운로드 URL: https://www.h2database.com/html/download-archive.html

버전 1.4.200을 설치합니다.

설치 파일의 압축을 푼 후 h2.bat 파일을 실행합니다.

JDBC URL을 프로토콜로 연결합니다.

멤버 테이블 생성

SQL
CREATE TABLE member(
   id bigint generated by default as identity,
   name VARCHAR(255),
  primary key (id)
);

스프링 H2 데이터베이스 연동

  • build.gradle의 dependencies에 implementation을 사용해 외부 라이브러리를 받습니다.
dependencies {
   implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
   implementation 'org.springframework.boot:spring-boot-starter-web'
   implementation 'org.springframework.boot:spring-boot-starter-jdbc'
   runtimeOnly 'com.h2database:h2'
   testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
  • application.properties에 DB 정보를 입력합니다.
spring.datasource.url=jdbc:h2:tcp://localhost/~/test
spring.datasource.driver-class-name=org.h2.Driver

이제 스프링에서 DB에 연결하는 환경설정을 완료했습니다.

다음으로 스프링에서 DB를 사용해보겠습니다.

이 글은 인프런 김영한 님의 스프링 입문 — 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술을 들으며 정리한 노트입니다.

댓글

GitHub 계정으로 로그인하시면 댓글과 질문을 남기실 수 있습니다. 남겨 주신 글은 이 저장소의 Discussions에 쌓입니다.

● main 214 posts UTF-8 LF © 2026 코징 RSS · GitHub