1. 下载
http://www.h2database.com
2. 安装
unzip h2-2013-07-28.zip
3. 启动与停止
仅仅本机web访问控制台
[root@INMSC4 bin]# ./h2.sh -web -browser
Web Console server running at http://192.168.1.21:8082 (only local connections)
其他人可以web访问控制台,同时支持tcp的jdbc连接(推荐)
[netcool@INMSC4 bin]$ ./h2.sh -web -browser -tcp -webAllowOthersWeb Console server running at http://192.168.1.21:8082 (others can connect)
TCP server running at tcp://192.168.1.21:9092 (only local connections)
3.2 停止
控制台登录page,有 Preferences 链接,点击进去,最下面有shutdown按钮;
3.3 H2的server属性文件在~/.h2.server.properties
该文件记录了server启动的方式及其他参数
[netcool@INMSC4 h2]$ more ~/.h2.server.properties
#H2 Server Properties
#Sun Oct 06 14:26:07 CST 2013
0=Generic JNDI Data Source|javax.naming.InitialContext|java\:comp/env/jdbc/Test|sa
1=Generic Firebird Server|org.firebirdsql.jdbc.FBDriver|jdbc\:firebirdsql\:localhost\:c\:/temp/firebird/test|sysdba
10=Generic Derby (Server)|org.apache.derby.jdbc.ClientDriver|jdbc\:derby\://localhost\:1527/test;create\=true|sa
11=Generic Derby (Embedded)|org.apache.derby.jdbc.EmbeddedDriver|jdbc\:derby\:test;create\=true|sa
12=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:~/test|sa
13=Generic H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://xxx.74.224.xxx\:9092/~/test|sa
2=Generic SQLite|org.sqlite.JDBC|jdbc\:sqlite\:test|sa
3=Generic DB2|COM.ibm.db2.jdbc.net.DB2Driver|jdbc\:db2\://localhost/test|
4=Generic Oracle|oracle.jdbc.driver.OracleDriver|jdbc\:oracle\:thin\:@localhost\:1521\:XE|sa
5=Generic MS SQL Server 2000|com.microsoft.jdbc.sqlserver.SQLServerDriver|jdbc\:microsoft\:sqlserver\://localhost\:1433;DatabaseName\=sqlexpress|sa
6=Generic MS SQL Server 2005|com.microsoft.sqlserver.jdbc.SQLServerDriver|jdbc\:sqlserver\://localhost;DatabaseName\=test|sa
7=Generic PostgreSQL|org.postgresql.Driver|jdbc\:postgresql\:test|
8=Generic MySQL|com.mysql.jdbc.Driver|jdbc\:mysql\://localhost\:3306/test|
9=Generic HSQLDB|org.hsqldb.jdbcDriver|jdbc\:hsqldb\:test;hsqldb.default_table_type\=cached|sa
webAllowOthers=true
webPort=8082
webSSL=false
4. 控制台登录与数据创建
4.1 启动方式./h2.sh -web -browser -webAllowOthers -tcp
url: http://ip:8082
jdbc url是jdbc:h2:test,或者jdbc:h2:~/test
4.2 启动方式./h2.sh -browser -webAllowOthers -tcp -tcpAllowOthers
url: http://ip:8082
jdbc url是jdbc:h2:test,或者jdbc:h2:~/test
jdbc:h2:tcp://ip:9092/~/test
5. 数据文件
登录方式确定了数据库的创建;
jdbc:h2:tcp://ip:9092/~/test
在用户目录下建一个test.h2.db数据库文件
jdbc:h2:tcp://ip:9092/aaa
在H2_HOME/bin下建一个aaa.h2.db数据库文件,如果bin下已经有这个文件,就不再新建。
6. help
./h2.sh --help
Starts the H2 Console (web-) server, as well as the TCP and PG server.
Usage: java org.h2.tools.Console <options>
When running without options, -tcp, -web, -browser and -pg are started.
Options are case sensitive. Supported options are:
[-help] or [-?] Print the list of options
[-url] Start a browser and connect to this URL
[-driver] Used together with -url: the driver
[-user] Used together with -url: the user name
[-password] Used together with -url: the password
[-web] Start the web server with the H2 Console
[-tool] Start the icon or window that allows to start a browser
[-browser] Start a browser connecting to the web server
[-tcp] Start the TCP server
[-pg] Start the PG server
其他参考
http://liureying.blog.163.com/blog/static/6151352010941092536/
http://wenku.baidu.com/view/f85d152a0066f5335a81218e.html
http://wenku.baidu.com/view/ba3eb50cf78a6529647d53c8.html
http://blog.youkuaiyun.com/firetaker/article/details/5909375