H2笔记

H2的JDBC URL很多,有内存,内嵌式还有TCP式,选用时避免独占式的URL。

驱动:org.h2.Driver
URL:jdbc:h2:tcp://localhost/~/dbname     这时的数据库文件位置在用户目录下,在迁移时不方便,改为:

 jdbc:h2:tcp://localhost/file:D:/zc/h2/server/dbname

更多的URL在:

http://blog.csdn.net/dingqinghu/article/details/6125501

 

H2打开远程连接

直接连接远程出错: org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.SocketTimeoutException: connect timed out: 192.168.1.202" [90067-168]
1.修改~/.h2.server.properties中的配置将tcpAllowOthers或webAllowOthers都打开(true)仍然无法通过程序连接远程H2数据库
webAllowOthers=true
webPort=8082
webSSL=false
错误信息:org.h2.jdbc.JdbcSQLException: Remote connections to this server are not allowed, see -tcpAllowOthers [90117-166]
2.使用命令bat启动h2 并打开tcp,OK

java -classpath h2.jar org.h2.tools.Server -tcp -tcpPort 8092 -tcpAllowOthers

 jdbc:h2:tcp://192.168.1.102:8082/~/dbname

 

你可能感兴趣的:(笔记)