H2 embedded database 접속 방법
샘플로 제공되는 도구들은 배포의 편리함을 고려해서 embedded DB를 주로 사용합니다. DB 테이블의 내용을 참조하거나 일부 값을 수정하기 위해 H2 database 파일에 접속하는 방법을 정리합니다.
Command line 사용
사전 준비
- h2 driver 다운로드 = http://www.h2database.com/html/main.html
All Platform (.zip) 다운로드 - DB 파일 경로 알아야 겠죠
- DB id/password가 있다면 알아내야 함
H2에 접속
$ > java -cp h2-<version>.jar org.h2.tools.Shell #예) java -cp h2-1.4.193.jar org.h2.tools.Shell
</끝>Welcome to H2 Shell 1.4.193 (2016-10-31)Exit with Ctrl+C[Enter] jdbc:h2:~/testURL jdbc:h2:file:/tmp/database/h2db #jdbc:h2:file: db 파일 경로 입력 (Windows라면 jdbc:h2:file:C:\tmp\database\h2db)[Enter] org.h2.DriverDriver[Enter] #아무것도 입력하지 않고 엔터를 쳐서 기본값 적용User sa #DB 사용자 이름 입력[Enter] HidePassword # DB 암호 입력하는 순서입니다. 암호가 설정되어 있지 않았다면 엔터를 계속 쳐줍니다PasswordConnectedCommands are case insensitive; SQL statements end with ';'help or ? Display this helplist Toggle result list / stack trace modemaxwidth Set maximum column width (default is 100)autocommit Enable or disable autocommithistory Show the last 20 statementsquit or exit Close the connection and exitsql> #접속 완료, use database 하지 않고 곧바로 sql query 하면 되겠습니다.sql> quit #접속 종료