gpt4 book ai didi

java - H2数据库连接

转载 作者:行者123 更新时间:2023-12-01 13:55:27 25 4
gpt4 key购买 nike

我需要用 Java ping H2 数据库。

为此,我向 ip_db:port: 发送 GET 请求

HttpUriRequest request = new HttpGet(url);
HttpResponse response = client.execute(request);

但我得到的只是 ClientProtocolException。

当我尝试在 Firefox 中打开 ip_db:port 时,我得到以下信息(为便于阅读而稍作编辑):

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 数据库?

最佳答案

你可以试试这个方法

try {
Class.forName("org.h2.Driver");
conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
console.append("CONNECTED" + '\n');
if(conn.isValid(1000){
//DO WHATEVER FOR ALIVENESS
}

} catch (Exception e) {
console.append(e.getMessage() + '\n');
}

关于java - H2数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19658505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com