SQL Error: 17008, SQLState: null

问题描述

每次程序运行一段时间以后,就报此错08-08-17 09:55:29 WARN JDBCExceptionReporter:71 - SQL Error: 17008, SQLState: null08-08-17 09:55:29 ERROR JDBCExceptionReporter:72 - 关闭的连接08-08-17 09:55:29 WARN JDBCExceptionReporter:71 - SQL Error: 17008, SQLState: null08-08-17 09:55:29 ERROR JDBCExceptionReporter:72 - 关闭的连接org.hibernate.exception.GenericJDBCException: could not execute queryCaused by: java.sql.SQLException: 关闭的连接我的的struts2 +hibernate3dao是 public Userinfo checkUserinfo(String name, String pwd) {Session session = HibernateSessionFactory.getSession();Transaction ta = session.beginTransaction();Userinfo userinfo = (Userinfo) session.createCriteria(Userinfo.class).add(Expression.eq("userinfoName", name)).add(Expression.eq("userinfoPassword", pwd)).uniqueResult();ta.commit();HibernateSessionFactory.closeSession();return userinfo;}问题补充:package com.shop.hibernate.util;import org.hibernate.HibernateException;import org.hibernate.Session;import org.hibernate.cfg.Configuration;/** * Configures and provides access to Hibernate sessions, tied to the * current thread of execution. Follows the Thread Local Session * pattern, see {@link http://hibernate.org/42.html }. */public class HibernateSessionFactory { /** * Location of hibernate.cfg.xml file. * Location should be on the classpath as Hibernate uses * #resourceAsStream style lookup for its configuration file. * The default classpath location of the hibernate config file is * in the default package. Use #setConfigFile() to update * the location of the configuration file for the current session. */ private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>(); private static Configuration configuration = new Configuration(); private static org.hibernate.SessionFactory sessionFactory; private static String configFile = CONFIG_FILE_LOCATION;static { try {configuration.configure(configFile);sessionFactory = configuration.buildSessionFactory();} catch (Exception e) {System.err.println("%%%% Error Creating SessionFactory %%%%");e.printStackTrace();} } private HibernateSessionFactory() { }/** * Returns the ThreadLocal Session instance. Lazy initialize * the <code>SessionFactory</code> if needed. * * @return Session * @throws HibernateException */ public static Session getSession() throws HibernateException { Session session = (Session) threadLocal.get();if (session == null || !session.isOpen()) {if (sessionFactory == null) {rebuildSessionFactory();}session = (sessionFactory != null) ? sessionFactory.openSession(): null;threadLocal.set(session);} return session; }/** * Rebuild hibernate session factory * */public static void rebuildSessionFactory() {try {configuration.configure(configFile);sessionFactory = configuration.buildSessionFactory();} catch (Exception e) {System.err.println("%%%% Error Creating SessionFactory %%%%");e.printStackTrace();}}/** * Close the single hibernate session instance. * * @throws HibernateException */ public static void closeSession() throws HibernateException { Session session = (Session) threadLocal.get(); threadLocal.set(null); if (session != null) { session.close(); } }/** * return session factory * */public static org.hibernate.SessionFactory getSessionFactory() {return sessionFactory;}/** * return session factory * *session factory will be rebuilded in the next call */public static void setConfigFile(String configFile) {HibernateSessionFactory.configFile = configFile;sessionFactory = null;}/** * return hibernate configuration * */public static Configuration getConfiguration() {return configuration;}}这是自动生成的问题补充:------------------------------------------------------Caused by: java.sql.SQLException: 关闭的连接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:269)at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:895)at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:802)at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)at org.hibernate.loader.Loader.doQuery(Loader.java:390)at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)at org.hibernate.loader.Loader.doList(Loader.java:1593)... 122 more

解决方案

楼主如果确定是这块代码的问题, 能不能把HibernateSessionFactory的代码贴出来, 可能有两个原因:1, 因为dao中你已经把session关闭, 如果Userinfo中使用了lazy加载, 那么就会拿不到session2, HibernateSessionFactory.getSession()这个方法中拿到的session是同一个, 也说是单例的, 多线程共用一个session, 如果有一个线程把session关掉, 而其它的线程还没有执行完, 提交的时候也会发现已关闭, 应该是每次开一个新的session
解决方案二:
没看出什么问题, 能不能把"Caused by: java.sql.SQLException: 关闭的连接 "这个异常的堆栈贴出来!也就是整个异常信息
解决方案三:
你的service层中是怎么用DAO的?感觉 你是在哪里没有打开session就开始使用查询。或者是你在DAO层中把session连接关闭了,然后又在service层中使用它。

时间: 2024-08-02 16:30:02

SQL Error: 17008, SQLState: null的相关文章

SQL Error: 933, SQLState: 42000

问题描述 执行程序的时候报出这个问题,麻烦各位帮我看看:2011-01-2009:00:56,062WARN[org.hibernate.util.JDBCExceptionReporter]-SQLError:933,SQLState:420002011-01-2009:00:56,062ERROR[org.hibernate.util.JDBCExceptionReporter]-ORA-00933:SQL命令未正确结束2011-01-2009:00:56,078WARN[org.apach

mysql-SQL Error: 1205, SQLState: 41000

问题描述 SQL Error: 1205, SQLState: 41000 [WARN ] 2015-04-19 09:00:00,760 method:org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77) SQL Error: 1205, SQLState: 41000 [ERROR] 2015-04-19 09:00:00,764 method:org.hibernate.u

DB2 SQL error: SQLCODE: -1117, SQLSTATE: 57019, SQLERRMC:SWZCYJS

问题描述 DBCP borrowObject failed: com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -1117, SQLSTATE: 57019, SQLERRMC: SWZCYJS2013-08-27 11:31:43 ERROR context.ContextLoader (ContextLoader.java:211) - Context initialization failedorg.springframewor

Sql与oracle中null值

  1 null值的介绍 NULL 是数据库中特有的数据类型,当一条记录的某个列为 NULL ,则表示这个列的值是未知的.是不确定的.既然是未知的,就有无数种的可能性.因此, NULL 并不是一个确定的值. 这是 NULL 的由来.也是 NULL 的基础,所有和 NULL 相关的操作的结果都可以从 NULL 的概念推导出来. 2 oracle中的null值介绍 在不知道具体有什么数据的时候,即未知,可以用NULL, 称它为空,ORACLE中,含有空值的表列长度为零.允许任何一种数据类型的字段为空

quartz集群-Quartz+Spring+Hibernate集群环境下 ClusterManager: Error managing cluster: null

问题描述 Quartz+Spring+Hibernate集群环境下 ClusterManager: Error managing cluster: null [2013-12-19 14:43:44] [ERROR] QuartzScheduler_quartzScheduler-NON_CLUSTERED_ClusterManager) - ClusterManager: Error managing cluster: null java.lang.reflect.UndeclaredThro

MySQL出现SQL Error (2013)连接错误的解决方法_Mysql

现象描述今天用heidisql登陆虚拟机的MySQL,登陆不上去.等待约一两分钟后出现错误提示:SQL Error (2013): Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0,如下图所示: 开始以为是远程TCP/IP  root只能通过localhost访问 ,后来新建用户,改为%后还是无果.尝试修改my.ini配置问题后问题消失. 解决办法在my.i

db2-ERRORCODE=-4472, SQLSTATE=null

问题描述 ERRORCODE=-4472, SQLSTATE=null 项目启动时报ERRORCODE=-4472, SQLSTATE=null,用的是db2数据库, 解决方案 解决了 好像是数据库的配置的地址有问题 解决方案二: 解决了 好像是数据库的配置的地址有问题

SQL error: cannot use the special principal &#039;sa&#039;

 SQL error: cannot use the special principal 'sa' 解决方案: use dbname EXEC sp_changedbowner 'dbname' 参考:https://msdn.microsoft.com/en-us/library/ms178630.aspx

SQL中IS NOT NULL与!=NULL的区别_数据库其它

平时经常会遇到这两种写法:IS NOT NULL与!=NULL.也经常会遇到数据库有符合条件!=NULL的数据,但是返回为空集合.实际上,是由于对二者使用区别理解不透彻. 默认情况下,推荐使用 IS NOT NULL去做条件判断,因为SQL默认情况下对WHERE XX!= Null的判断会永远返回0行,却不会提示语法错误. 这是为什么呢? SQL Server文档中对Null值的比较运算定义了两种规则,如在SQL Server 2000中: 规则一是是ANSISQL(SQL-92)规定的Null