0
我需要在Java中ping H2數據庫。H2數據庫連接
爲了做到這一點,我發送一個GET請求來ip_db:端口:
HttpUriRequest request = new HttpGet(url);
HttpResponse response = client.execute(request);
但我得到的是ClientProtocolException。
當我嘗試打開ip_db:在Firefox端口,我得到以下信息(略加編輯,以便閱讀):
90047BVersion mismatch, driver version is "0" but server version is "12"яяяя_їXorg.h2.jdbc.JdbcSQLException: Version mismatch, driver version is "0" but server version is "12" [90047-173]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
at org.h2.message.DbException.get(DbException.java:171)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:88)
at java.lang.Thread.run(Thread.java:724)
這裏的H2日誌:
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.ConnectException: Connection refused: my_ip" [90067-173]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
at org.h2.message.DbException.get(DbException.java:160)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:407)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:295)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:105)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
at org.h2.Driver.connect(Driver.java:73)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at org.h2.tools.CreateCluster.process(CreateCluster.java:137)
at org.h2.tools.CreateCluster.runTool(CreateCluster.java:85)
at org.h2.tools.CreateCluster.main(CreateCluster.java:52)
我需要做什麼來做ping數據庫?
坪數據庫?你想建立活力嗎?您是否可能將JDBC URL與HTTP URL混淆?你的'url'是什麼? –
是的,我試圖建立活力。可能會讓人困惑。 url是http:// ip_db:9092 - 與我使用Firefox相同的ip。 – fskrypter
那麼我會說你已經完成了你的目標 - 如果數據庫不活着,你會得到['ConnectException'](http://docs.oracle.com/javase/7/docs/api/java /net/ConnectException.html)而不是:-) –