【发布时间】:2015-01-27 03:57:16
【问题描述】:
我正在尝试逐段阅读给定的网页链接、网页并将该数据插入数据库。
每次阅读并插入大约 20 个网页后,都会出现以下错误消息。
我在Xampp mysql 服务器上工作。清除历史记录后,cookies 会再次正常工作。然后在阅读网页并插入相同的错误之后。
没有合适的解决方案吗?一些堆栈溢出问题提到了编辑一些配置文件的一些想法。
因为我在 Windows 环境中工作,我不清楚他们在提到什么。他们提到增加最大连接。但不清楚他们提到的我如何编辑某些文件(不清楚该配置文件在 Windows 环境中的存储位置)。
错误信息:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
... 12 more
Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
... 13 more
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source)
【问题讨论】:
-
请检查您的代码以确保您在 JDBC 连接(和您的结果集)上正确调用
close()。这对我来说就像你的 MySQL 服务器被包含连接泄漏的应用程序(你的 Java 东西)击中。 -
@OllieJones 插入数据库后,我将在 finally 块中关闭连接。它也想关闭一些连接阅读类吗?根据下面的“Vishvesh Phadnis 答案”,我的问题解决了一些问题。但几分钟后,同样的事情又发生了。怎么了?