内部异常:java.sql.SQLException:无效状态,Connection对象已关闭 [英] Internal Exception: java.sql.SQLException: Invalid state, the Connection object is closed

查看:522
本文介绍了内部异常:java.sql.SQLException:无效状态,Connection对象已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Eclipse Persistence Services-2.1.1.v20100817-r8050的JSF应用程序,有时会出现以下错误:

I have a JSF application that uses Eclipse Persistence Services - 2.1.1.v20100817-r8050, and I sometimes get the following error:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.1.v20100817-r8050):    org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid state, the Connection object is closed.
Error Code: 0
Call: SELECT XXXXX FROM XXXXX
bind => [/Home/Footer/]
Query: ReadAllQuery(name="WWW.find" referenceClass=WWW sql="SELECT XXXXX FROM XXXXX")

我不知道是什么原因造成的.在返回q.getResultList();"上的以下函数中引发了异常.线.

I have no idea what is causing it. The exception is thrown in the following function on the "return q.getResultList();" line.

public List<WWW> find(String url) {
    }
    EntityManager em = getEntityManager();
    try {
        Query q = em.createNamedQuery("WWW.find");
        q.setParameter("url", url);
        return q.getResultList();
    } finally {
        em.close();
    }
}


我们有SQL Server 2005,数据库未关闭.这始终是最近发生的事情.以下是我们在persistence.xml文件中设置的属性.关于此方面应有何变化的任何评论?


We have SQL Server 2005 and the database isn't down. This is more of a recent thing to consistently happen. Below is the properties that we set in the persistence.xml file. Any comments on what should change in this?

<properties>
  <property name="javax.persistence.jdbc.password" value="password"/>
  <property name="javax.persistence.jdbc.user" value="user"/>
  <property name="javax.persistence.jdbc.driver" value="net.sourceforge.jtds.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.url" value="jdbc:jtds:sqlserver://SERVER:1433/DB"/>
  <property name="eclipselink.ddl-generation" value="none"/>
  <property name="eclipselink.jdbc.timeout" value="20"/>
  <property name="eclipselink.jdbc.connections.wait-timeout" value="20"/>
  <property name="javax.persistence.query.timeout" value="20"/>
  <property name="eclipselink.allow-zero-id" value="true"/>
</properties>

这是我编辑过的课程 公共类WWWJpaController {

Here is my edited class public class WWWJpaController {

public WWWWJpaController() {
    emf = Persistence.createEntityManagerFactory("properties");
}

public WWWWJpaController(String unitName) {
    emf = Persistence.createEntityManagerFactory(unitName);
}

private EntityManagerFactory emf = null;

public EntityManager getEntityManager() {
    return emf.createEntityManager();
}

public List<WWW> find(String url) {
    EntityManager em = getEntityManager();
    try {
        Query q = em.createNamedQuery("WWW.find");
        q.setParameter("url", url);
        return q.getResultList();
    }finally{
        em.close();
    }
}

}

推荐答案

我的猜测是您的数据库连接已超时,或者数据库已关闭. 您可能需要重试查询或重新连接会话.

My guess is your database connection has timed out, or your database is down. You may need to retry the query, or re-connect your session.

您如何配置连接池以及使用的数据库是什么?

How have you configured your connection pooling and what database are you using?

这篇关于内部异常:java.sql.SQLException:无效状态,Connection对象已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆