连接有一个远程数据库
我从远程计算机使用H2数据库作为DBMS,因此我启用了从浏览器远程访问,如下所示:
webAllowOthers=true
但是当我尝试从我的java应用程序连接到服务器时,我从H2获得此错误:
remote connections to this server are not allowed
截图:
并且已经在查看代码分析器(错误代码:90117):
REMOTE_CONNECTION_NOT_ALLOWED = 90117
如果不允许远程连接,则尝试从另一台计算机连接到TCP服务器时会引发代码90117的错误。 要允许远程连接,请使用选项-tcpAllowOthers启动TCP服务器,如下所示:
java org.h2.tools.Server -tcp -tcpAllowOthers
或者,从应用程序启动服务器时,使用: Server server = Server.createTcpServer(“ – tcpAllowOthers”); server.start();
我不明白如何激活tcpAllowOthers ,它在.h2.server.properties中不存在?
有两种不同的服务器:
- 用于运行H2控制台工具(GUI工具)的Web控制台服务器。 它只能由浏览器访问。
- 使用客户端/服务器模式时允许连接使用JDBC的应用程序的TCP服务器(
jdbc:h2:tcp://localhost/~/test
)
文件.h2.server.properties
仅用于Web控制台服务器。 它只支持webAllowOthers=true
。 TCP服务器不使用此文件。
要启用对TCP服务器的远程访问,需要使用选项-tcpAllowOthers
启动TCP服务器。 要启动Web控制台服务器(H2控制台工具) 和启用了远程连接的TCP服务器,您需要使用:
java -jar h2*.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser
(这也启动浏览器)