cs程序hibernate连接数据库问题
求各位大神帮忙哦!我遇到个棘手的问题!我编写了个cs的程序,用fatjar打成可执行的jar包运行,程序里面使用了hibernate,数据库是oracle9i。程序运行没问题,但是如果有数据访问数据库后,长时间没有数据,会出现如下错误。org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.jx.util.BaseHibernateDAO.find(BaseHibernateDAO.java:72)
at com.jx.dao.ObjectDao.getByHql(ObjectDao.java:19)
at com.jx.business.biz.PositionBiz.Enter(PositionBiz.java:37)
at com.jx.Enter.EnterClass.position(EnterClass.java:29)
at com.foyoo.gps.ServerThread.run(ServerThread.java:93)
Caused by: java.sql.SQLException: Io 异常: Broken pipe
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:389)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:413)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:119)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:92)
at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:950)
at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:802)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 12 more
我尝试过使用c3p0,但是不知道为何,c3p0使用方法很简单,但是集成之后c3p0报错,无法访问数据库。我现在搞不懂到底如何解决哦,求大神帮忙哦 --------------------编程问答-------------------- 自己找到个解决办法。我是用myeclipse自动生成的HibernateSessionFactory这个类,里面有个rebuildSessionFactory的方法。我是这么考虑的,由于方法中存在这段代码
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
它是静态的,去buildSessionFactory。那么估计是创建之后数据库连接超时,一般我出现错误重启程序即可,那么我重新创建连接会话就应该能解决。我再操作的4个基类(增删改查)里面都捕获异常,如果出现异常说明就是连接失败的问题,那么就调用重新创建会话的方法,应该跟重启差不多,不知道啥结果哦。。。。 --------------------编程问答-------------------- 没人回答么?随便来个人回答下我结贴也好哦!
补充:Java , Java相关