Skip to content

Instantly share code, notes, and snippets.

@olivedrabtype
Created January 31, 2017 14:49
Show Gist options
  • Save olivedrabtype/6f7877f0e3e8fe1e8f13779e18e1064b to your computer and use it in GitHub Desktop.
Save olivedrabtype/6f7877f0e3e8fe1e8f13779e18e1064b to your computer and use it in GitHub Desktop.

H2 Database

http://www.h2database.com/html/main.html

  • Pure Java
  • Memory Mode
  • Encrypted Database
  • ODBC Driver
  • Full text Search
  • Multi Version Concurrency

Gradle Setting

edit build.gradle

dependencies {
    runtime('com.h2database:h2')
}

runtime 프로젝트를 실행할 때 필요한 의존 라이브러리들. 기본적으로 compile을 모두 포함한다.
compile 프로젝트를 컴파일할 때 필요한 의존 라이브러리들

Spring Security Setting

edit WebSecurityConfiguration.java

@Override
public void configure(WebSecurity web) throws Exception {
	web
		.ignoring()
		.antMatchers("/h2-console/**")
}

H2 Setting

edit application.yml

spring:
  profiles: h2database
  jpa:
    generate-ddl: true
    hibernate:
      ddl-auto: create-drop
  h2:
    console:
      enabled: true
      path: /h2-console
  datasource:
#    url: jdbc:h2:mem:mcdonald
#    initialize: true
#    schema: classpath:database/sql/greeting.sql,classpath:database/sql/ddl_*.sql
#    data: classpath:database/sql/dml_*.sql
    
    type: org.apache.tomcat.jdbc.pool.DataSource
    driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
    url: jdbc:log4jdbc:h2:mem:mcdonald
    username: sa
    password: test
    initialize: true
    schema: classpath:database/sql/greeting.sql,classpath:database/sql/ddl_*.sql
    data: classpath:database/sql/dml_*.sql

H2 Console 접속

  • application.yml 에서 지정한 경로로 접근한다.

http://localhost:8081/manager/h2-console

  • 지정한 정보를 입력후 [Connect]
  • JDBC URL : jdbc:h2:mem:mcdonald
  • User Name: sa
  • Password: test

Screen_Shot_2017-01-06_at_4.54.17_PM

  • 접속화면에서 DB정보확인과 쿼리실행이 가능하다.
    Screen_Shot_2017-01-06_at_4.56.48_PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment