2015-02-09 94 views
0

请仔细阅读下面我在Java Swing中编写的代码来连接局域网中的H2数据库,但是我做了Google,但没有得到正确的解决方案。无法访问局域网中的H2数据库

try { 
     //192.168.0.200 is Partner IP Address 
     Class.forName("org.h2.Driver"); 
     Connection connection = DriverManager.getConnection("jdbc:h2:tcp://192.168.0.200/~/testingDB", "sa", ""); 
     System.out.println("Connected" + connection); 
    } catch (Exception e) { 
     System.out.println("Here" + e.toString()); 
    } 

我想连接H2使用IPV4地址在另一台计算机上安装的数据库,但出现以下错误。

Hereorg.h2.jdbc.JdbcSQLException: Remote connections to this server are not allowed, see -tcpAllowOthers [90117-184] 
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) 
at org.h2.message.DbException.get(DbException.java:179) 
at org.h2.message.DbException.get(DbException.java:155) 
at org.h2.message.DbException.get(DbException.java:144) 
at org.h2.server.TcpServerThread.run(TcpServerThread.java:83) 
at java.lang.Thread.run(Unknown Source) 

我在合作伙伴以及我的电脑给出了下面的命令,但仍然收到了同样的错误。

http://www.windows-commandline.com/enable-remote-desktop-command-line/

请帮我找到解决方案。

+0

H2是否在服务器模式下运行? – MadProgrammer 2015-02-09 06:53:44

+0

你的意思是说在Generic H2(服务器)上。我在浏览器上试过,它运行完美,但没有通过给定的Java代码。 – user4545129 2015-02-09 07:00:20

+0

H2服务器不在TCP模式下 – MadProgrammer 2015-02-09 07:01:26

回答

1

您需要使用-tcpAllowOthers选项启动H2服务器。出于安全原因,此选项默认情况下未启用。

+0

@ Thomas谢谢您的回复,但我该如何启用此选项..... – user4545129 2015-02-10 14:49:11

+0

@ user4545129我建议阅读文档。 – 2015-02-10 14:59:24