Java 连接有一个远程数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9838041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connection has a remote Database
提问by Marwen Trabelsi
I use H2 Database as DBMS from a remote computer,so I enabled remote access from a browser as follows:
我从远程计算机使用 H2 数据库作为 DBMS,因此我启用了从浏览器的远程访问,如下所示:
webAllowOthers=true
but when i try to connect to the server from my java application i get this error from H2:
但是当我尝试从我的 Java 应用程序连接到服务器时,我从 H2 收到此错误:
remote connections to this server are not allowed
screenshot:
截屏:
And also already looking into the code Analyzer with (Error Code: 90117):
并且已经在查看代码分析器(错误代码:90117):
REMOTE_CONNECTION_NOT_ALLOWED = 90117
REMOTE_CONNECTION_NOT_ALLOWED = 90117
The error with code 90117 is thrown when trying to connect to a TCP server from another machine, if remote connections are not allowed. To allow remote connections, start the TCP server using the option -tcpAllowOthers as in:
如果不允许远程连接,则尝试从另一台计算机连接到 TCP 服务器时会抛出代码为 90117 的错误。要允许远程连接,请使用选项 -tcpAllowOthers 启动 TCP 服务器,如下所示:
java org.h2.tools.Server -tcp -tcpAllowOthers
java org.h2.tools.Server -tcp -tcpAllowOthers
Or, when starting the server from an application, use: Server server = Server.createTcpServer("-tcpAllowOthers"); server.start();
或者,当从应用程序启动服务器时,使用: Server server = Server.createTcpServer("-tcpAllowOthers"); server.start();
I do not understand how to activate the tcpAllowOthers, it does not exist in .h2.server.properties?
我不明白如何激活tcpAllowOthers,它在.h2.server.properties中不存在?
采纳答案by Thomas Mueller
There are two different server:
有两个不同的服务器:
- the Web Console server that is used to run the H2 Console tool (the GUI tool). It can be accessed by a browser only.
- the TCP server that allows to connect an application that uses JDBC, when using the client/server mode (
jdbc:h2:tcp://localhost/~/test
)
- 用于运行 H2 控制台工具(GUI 工具)的 Web 控制台服务器。它只能通过浏览器访问。
- 当使用客户端/服务器模式 (
jdbc:h2:tcp://localhost/~/test
)时,允许连接使用 JDBC 的应用程序的 TCP 服务器
The file .h2.server.properties
is only used for the Web Console server. It only supports webAllowOthers=true
. This file is not used by the TCP server.
该文件.h2.server.properties
仅用于 Web 控制台服务器。它只支持webAllowOthers=true
. TCP 服务器不使用此文件。
To enable remote access to the TCP server, you need to start the TCP server using the option -tcpAllowOthers
. To start both the Web Console server (the H2 Console tool) andthe TCP server with remote connections enabled, you would need to use:
要启用对 TCP 服务器的远程访问,您需要使用选项启动 TCP 服务器 -tcpAllowOthers
。要在启用远程连接的情况下启动Web 控制台服务器(H2 控制台工具)和TCP 服务器,您需要使用:
java -jar h2*.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser
(this also starts a browser)
(这也会启动浏览器)