【问题标题】:I can not connect database from Netbeans我无法从 Netbeans 连接数据库
【发布时间】:2013-05-31 12:52:17
【问题描述】:

我在互联网上有一个 MySQL 数据库。我可以通过浏览器和 MySQL Workbench 成功访问它。我将数据库添加到 Netbeans。当我尝试从 Netbeans 连接数据库时,出现此错误:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
Error code 0, SQL state 08S01: Communications link failure

The last packet successfully received from the server was 14.047 milliseconds ago.  The last packet sent successfully to the server was 1 milliseconds ago.

我还尝试使用 RESTful Web 服务连接数据库。我收到此错误:

GET RequestFailed RequestFailed --> Status: (500) 
Response: {
HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Error Code: 0
Call: SELECT o_id, isim, not, yas FROM ogrenci
Query: ReadAllQuery(referenceClass=Ogrenci sql="SELECT o_id, isim, not, yas FROM ogrenci")
root cause

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Error Code: 0
Call: SELECT o_id, isim, not, yas FROM ogrenci
Query: ReadAllQuery(referenceClass=Ogrenci sql="SELECT o_id, isim, not, yas FROM ogrenci")
root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
root cause

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 228.471 milliseconds ago.  The last packet sent successfully to the server was 11 milliseconds ago.
root cause

java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.

【问题讨论】:

  • 你能提供你用来连接数据库的代码吗?
  • Netbeans 的“服务”选项卡下有数据库。我右键单击数据库,然后单击新建连接。然后我输入必要的信息。
  • 在执行查询之前连接正在关闭。
  • 不要关闭连接并尝试一次。你会找到原因的。
  • 尝试将它设置得更高,比如 300(5 分钟),看看它是否有效

标签: java mysql database netbeans glassfish


【解决方案1】:

尝试增加wait_timeoutmysql变量:

SET wait_timeout=300;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    • 2016-03-20
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多