H2数据库(嵌入式)连接超时

发布于 2024-10-07 20:04:30 字数 1704 浏览 8 评论 0原文

连接到数据库时出现以下异常:

org.h2.jdbc.JdbcSQLException: Connection is broken: "connect timed out" [90067-142]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    at org.h2.message.DbException.get(DbException.java:156)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:326)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:248)
    at org.h2.engine.SessionRemote.createSession(SessionRemote.java:214)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95)
    at org.h2.Driver.connect(Driver.java:73)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
................
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:109)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:91)
    at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:92)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:322)
    ... 38 more

连接字符串如下所示:

jdbc:h2:C:\Users\Michael\.myadd\db;AUTO_SERVER=TRUE;CIPHER=AES

出现此类异常的原因是什么?

谢谢!

I get the following exception when connecting to the database:

org.h2.jdbc.JdbcSQLException: Connection is broken: "connect timed out" [90067-142]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    at org.h2.message.DbException.get(DbException.java:156)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:326)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:248)
    at org.h2.engine.SessionRemote.createSession(SessionRemote.java:214)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95)
    at org.h2.Driver.connect(Driver.java:73)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
................
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:109)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:91)
    at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:92)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:322)
    ... 38 more

The connection string looks as follows:

jdbc:h2:C:\Users\Michael\.myadd\db;AUTO_SERVER=TRUE;CIPHER=AES

What can be the reason for such exception?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

说不完的你爱 2024-10-14 20:04:30

对于 h2,默认连接池大小为 10,登录超时为 30 秒,如果我们长时间同时获取 10 个连接,则获取连接的新请求将超时。
对于我的情况,发现由于代码中的错误,连接没有关闭。我们可以增加最大连接数。

connectionPool.setMaxConnections(20);

但默认情况下,数据库管理器是单线程的,因此更多的连接不会获得任何性能。

For h2 default connection pool size is 10 and login timeout is 30 sec, if we acquire 10 simultaneous connection for longer period then new request to acquire connection will be timed out.
for my case found that connection was not getting closed due to bug in code. we can increase max connection count.

connectionPool.setMaxConnections(20);

but by default db manager is single threaded so more connection will not gain any performance.

眼藏柔 2024-10-14 20:04:30

我猜您阅读了有关自动混合模式的文档?很难说问题是什么,因为对我来说它有效。您可以发布文件 C:\Users\Michael.myadd\db.lock.db 的内容吗?对我来说,它是(连接后):

#FileLock
#Tue Dec 14 22:29:22 CET 2010
id=12ce6c9a16a912077e514cc6fff231e91b09d2dbe43
method=file
server=192.168.0.126\:52068

这意味着数据库已打开,打开它的客户端在此 IP 地址和端口上启动了服务器。

I guess you read the docs about the automatic mixed mode? It's hard to say what the problem is, because for me it works. Could you post the content of the file C:\Users\Michael.myadd\db.lock.db ? For me it is (after connecting):

#FileLock
#Tue Dec 14 22:29:22 CET 2010
id=12ce6c9a16a912077e514cc6fff231e91b09d2dbe43
method=file
server=192.168.0.126\:52068

That means the database is open, and the client that opened it started a server on this IP address and port.

单调的奢华 2024-10-14 20:04:30

先重新启动计算机(^_^)/重新开始

我尝试了所有方法,但似乎唯一有效的是重新启动我的计算机。

以下是工作的列表:

  1. 刷新项目并
  2. 关闭和打开应用程序
  3. 调整代码

我什至可以在 H2 控制台中看到数据库工作正常,但 Eclipse 直到它才连接到它我重新启动了电脑。

我多次记录此错误:
“连接:org.h2.jdbc.JdbcSQLNonTransientConnectionException:连接已损坏:“java.net.SocketTimeoutException:连接超时:...”

我在午餐前重新启动以连接到数据库,并在我的电脑上工作了一个小时。它睡过午饭,然后下午我不得不重新启动计算机才能连接数据库。

其他评论是关于 MaxConnections 的,但我是唯一使用该数据库的人。

Restart your computer first (^_^)/ 再起動

I tried everything, but the only thing that seems to work is restarting my computer.

Here's a list of things that did NOT work:

  1. refreshing the project and maven
  2. closing and opening applications
  3. adjusting the code

I could even see the database working fine in the H2 Console, but eclipse would not connect to it until I restarted my computer.

I logged this error many times:
"connection: org.h2.jdbc.JdbcSQLNonTransientConnectionException: Connection is broken: "java.net.SocketTimeoutException: Connect timed out: ..."

I restarted to connect to the database before lunch, and worked on my pc for an hour. It slept through lunch, then I had to restart my computer again to connect to the database in the afternoon.

Other comments are about MaxConnections, but I am the only one using this database.

阳光下慵懒的猫 2024-10-14 20:04:30

当某些进程锁定对数据库文件的访问时,可能会发生这种情况,尤其是在 Windows 上。测试它的简单方法是尝试删除该文件(如果您可以轻松地重新创建它)。然后你必须找到该进程并杀死它。

It could happen, especially on Windows, when some process locks access to the db file. Easy way how to test it is to try to delete the file, if you can recreate it easily. Then you have to find the process and kill it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文