2015-02-09 46 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