2012-03-23 137 views
7

我使用H2数据库的DBMS从远程计算机,所以我启用了从浏览器远程访问如下:连接有一个远程数据库

webAllowOthers=true 

但是当我试图从我的Java应用程序连接到服务器我得到这个错误从H2:

remote connections to this server are not allowed 

截图: enter image description here

而且也已经寻找到的代码分析仪(错误代码:9011 7):

REMOTE_CONNECTION_NOT_ALLOWED = 90117

与代码90117的错误尝试从另一台机器连接到TCP服务器,如果远程连接不允许时被抛出。要允许远程连接,使用选项-tcpAllowOthers在启动TCP服务器:

的Java org.h2.tools.Server -TCP -tcpAllowOthers

或者,从应用程序启动服务器时,使用: Server server = Server.createTcpServer(“ - tcpAllowOthers”); server.start();

我不明白如何激活tcpAllowOthers,它不.h2.server.properties存在吗?

回答

12

有两种不同的服务器:

  • 用来运行H2控制台工具(GUI工具)的Web控制台服务器。它只能通过浏览器访问。
  • TCP服务器,它允许连接使用客户端/服务器模式(jdbc:h2:tcp://localhost/~/test

文件.h2.server.properties仅用于Web控制台服务器时使用JDBC,一个应用程序。它只支持webAllowOthers=true。该文件不被TCP服务器使用。

要启用远程访问TCP服务器,您需要使用选项-tcpAllowOthers启动TCP服务器。要启动这两个Web控制台服务器(H2控制台工具)与远程连接启用了TCP服务器,您需要使用:

java -jar h2*.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser 

(这还会启动一个浏览器)

+0

+1快速反应,答案已经在http://www.h2database.com/html/tutorial.html#console_settings,:-) – 2012-03-23 11:35:02