java.sql.SQLException:Io exception:由peer重置连接:套接字写入错误 [英] java.sql.SQLException: Io exception: Connection reset by peer: socket write error

查看:128
本文介绍了java.sql.SQLException:Io exception:由peer重置连接:套接字写入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用oracle 11g,hibernate 3和jsf2.I部署我的应用程序was7.Every事情进行顺利,但当我尝试登录后5-6小时它是给我错误



错误org.hibernate.util.JDBCExceptionReporter - Io异常:连接由对等重置:套接字写错误
[5/28/13 11:31: 25:048 IST] 00000024 SystemErr R org.hibernate.exception.GenericJDBCException:无法在org.hibernate上执行查询
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
。 exception.SQLStateConverter.convert(SQLStateConverter.java:114)
在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
在org.hibernate.loader.Loader.doList(Loader。 java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
在org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
在org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
在org.hibernate .engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list (QueryImpl.java:102)

我无法找到如何解决这个错误。 。提前。



现在我已经通过代码解决了这个问题,但我不知道是正确的方式或not.will你建议我,我应该继续这个解决方案不行。

  public class ApplicationUtilityBean implements Serializable {
private SessionFactory sessionFactory;
private AnnotationConfiguration cfg;
public String filePath;
private String realPath = Config.PATH;

public ApplicationUtilityBean()throws URISyntaxException {
getConnection();
}

public void getConnection(){
URL r = this.getClass()。getClassLoader()。getResource(hibernate.cfg.xml);
cfg = new AnnotationConfiguration();
cfg.configure(r);
String pwd = cfg.getProperty(hibernate.connection.password);
TripleDESEncryption tripledesenc = null;
try {
tripledesenc = new TripleDESEncryption();
} catch(Exception e){
e.printStackTrace();
}
cfg.setProperty(hibernate.connection.password,
tripledesenc.decrypt(pwd));
sessionFactory = cfg.buildSessionFactory();

System.out.println(cfg:+ cfg);
System.out.println(sessionFactory:+ sessionFactory);
}

public Session getSession(){
System.out.println(Going to get session);
会话session = null;
try {
System.out.println(cfg is:+ cfg);
System.out.println(sessionFactory:+ sessionFactory);
session = sessionFactory.openSession();
if(session!= null){
try {
Transaction trxn = session.beginTransaction();
Query queryResult = session.createSQLQuery(select * from dual);
List< GTS_USER> listgtsuser = queryResult.list();
} catch(Exception e){
e.printStackTrace();
System.out.println(正在创建新连接............);
session.close();
sessionFactory.close();
getConnection();
session = sessionFactory.openSession();
}
}
} catch(Exception e){
e.printStackTrace();
}
return session;
}

}



和我的hibernate配置文件是

 < hibernate-configuration> 
< session-factory>

< property name =hibernate.cache.region.factory_class> net.sf.ehcache.hibernate.EhCacheRegionFactory< / property>
< property name =hibernate.cache.use_query_cache> true< / property>
< property name =hibernate.cache.use_second_level_cache> true< / property>

< property name =hibernate.connection.driver_class> oracle.jdbc.OracleDriver< / property>
< property name =hibernate.connection.url> jdbc:oracle:thin:@xxxxxxxxx:1521:HMS< / property>
< property name =hibernate.connection.username> xxxxx< / property>
< property name =hibernate.connection.password> xxxxxxxxxxx< / property>
< property name =hibernate.connection.pool_size> 10< / property>
< property name =show_sql> true< / property>
< property name =dialect> org.hibernate.dialect.OracleDialect< / property>
< property name =hibernate.hbm2ddl.auto> update< / property>


解决方案

您可能面临数据库连接超时。在每个数据库上,当连接打开并且在一段时间内没有活动时,会出现超时。您需要一个连接池管理器。



如果安装 c3p0 并正确配置它将允许hibernate保持您的



这里是一个示例 MySQL和Hibernate的确,但它是一样的。您必须包括 c3p0.jar ,并将其添加到您的休眠配置文件中:

 < property name =c3p0.min_size> 5< / property> 
< property name =c3p0.max_size> 20< / property>
< property name =c3p0.timeout> 1800< / property>
< property name =c3p0.max_statements> 50< / property>
< property name =hibernate.connection.provider_class> org.hibernate.connection.C3P0ConnectionProvider< / property>

确保配置 c3p0.timeout 到您的数据库!


I am using oracle 11g,hibernate 3 and jsf2.I deployed my application on was7.Every thing is going well but when i try to login after 5-6 hours it is gives me error

ERROR org.hibernate.util.JDBCExceptionReporter - Io exception: Connection reset by peer: socket write error
[5/28/13 11:31:25:048 IST] 00000024 SystemErr     R org.hibernate.exception.GenericJDBCException: could not execute query
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2231)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
    at org.hibernate.loader.Loader.list(Loader.java:2120)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)

I unable to find out how this error to solve.Please help me.Thanks in advance.

Now i have solved this problem by code but i don'nt know is it proper way or not.will you suggest me, i should continue with this solution on not.

public class ApplicationUtilityBean implements Serializable {
private SessionFactory sessionFactory;
private AnnotationConfiguration cfg;
public String filePath;
private String realPath = Config.PATH;

public ApplicationUtilityBean() throws URISyntaxException {
    getConnection();
}

public void getConnection() {
    URL r = this.getClass().getClassLoader().getResource("hibernate.cfg.xml");
            cfg = new AnnotationConfiguration();
    cfg.configure(r);
    String pwd = cfg.getProperty("hibernate.connection.password");
    TripleDESEncryption tripledesenc = null;
    try {
        tripledesenc = new TripleDESEncryption();
    } catch (Exception e) {
        e.printStackTrace();
    }
    cfg.setProperty("hibernate.connection.password",
            tripledesenc.decrypt(pwd));
    sessionFactory = cfg.buildSessionFactory();

    System.out.println("cfg: " + cfg);
    System.out.println("sessionFactory: " + sessionFactory);
}

public Session getSession() {
    System.out.println("Going to get session");
    Session session = null;
    try {
        System.out.println("cfg is: " + cfg);
        System.out.println("sessionFactory: " + sessionFactory);
        session = sessionFactory.openSession();
        if(session != null){
            try {
                Transaction trxn = session.beginTransaction();
                Query queryResult = session.createSQLQuery("select * from dual");
                List<GTS_USER>listgtsuser = queryResult.list();     
                                } catch (Exception e) {                 
                e.printStackTrace();
                System.out.println("Creating new connection............");
                session.close();
                sessionFactory.close();
                getConnection();
                session = sessionFactory.openSession();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return session;
}

}

and my hibernate config file is

<hibernate-configuration>
<session-factory>

    <property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
    <property name="hibernate.cache.use_query_cache">true</property>
    <property name="hibernate.cache.use_second_level_cache">true</property>

    <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:@xxxxxxxxx:1521:HMS</property>
    <property name="hibernate.connection.username">xxxxx</property>
    <property name="hibernate.connection.password">xxxxxxxxxxx</property>
    <property name="hibernate.connection.pool_size">10</property> 
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.hbm2ddl.auto">update</property>

解决方案

You are probably facing a database connection timeout. On every databases there is a timeout when a connection is open and there is no activity for a certain period. You need a connection pool manager.

If you install c3p0 and configure it correctly it will allow hibernate to keep your connection alive and/or re-open it when you need it.

Here is an example for MySQL and Hibernate indeed but it is the same. You have to include c3p0.jar and also add this to your hibernade configuration file :

<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

Make sure to configure c3p0.timeout according to your database!

这篇关于java.sql.SQLException:Io exception:由peer重置连接:套接字写入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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