1.H2的URL地址:
(1)远程:jdbc:h2:tcp://localhost/~/test 或 jdbc:h2:tcp://192.168.6.6/E:\Develop\H2\db\test
(2)本地:jdbc:h2:~/test 或 jdbc:h2:E:\Develop\H2\db\test
2. 命令行创建数据库或登录(连接)已有的数据库:(windows的cmd窗口和linux的shell窗口都一样)
java -cp h2-1.4.200.jar org.h2.tools.Shell
[root@cdh04 h2]# java -cp h2-1.4.200.jar org.h2.tools.Shell
Welcome to H2 Shell 1.4.200 (2019-10-14)
Exit with Ctrl+C
[Enter] jdbc:h2:~/test
URL jdbc:h2:/usr/h2/test #此处是本地数据库,还可以连接远程数据库,如:
[Enter] org.h2.Driver
Driver #此处没有填写驱动,默认就是系统提供的模板 “org.h2.Driver”
[Enter]
User root
Password
roType the same password again to confirm database creation.
Password
Connected
Commands are case insensitive; SQL statements end with ';'
help or ? Display this help
list Toggle result list / stack trace mode
maxwidth Set maximum column width (default is 100)
autocommit Enable or disable autocommit
history Show the last 20 statements
quit or exit Close the connection and exit
sql> #到这里,说明已经连接上了,可以开始操作数据库了
注意:当连接远程数据库时,服务器端的启动数据库的命令行要加上参数 -tcpAllowOthers 或 -webAllowOthers,如下:
E:\Develop\H2\bin>java -jar h2-1.4.200.jar -tcpAllowOthers
Web Console server running at http://192.168.8.5:8082 (others can connect)
TCP server running at tcp://192.168.8.5:9092 (others can connect)
PG server running at pg://192.168.8.5:5435 (only local connections)
E:\Develop\H2\bin>java -jar h2-1.4.200.jar -webAllowOthers
Web Console server running at http://192.168.8.5:8082 (others can connect)
TCP server running at tcp://192.168.8.5:9092 (only local connections)
PG server running at pg://192.168.8.5:5435 (only local connections)
3.