0

I'm using jboss5.1 with spring as the system's architecture. The version of mysql is 5.6.12, and the version of jdk is 1.7. Scenario : Because I need update the record which the system inserted into the DB no long before,
I try to get the id of the record while executing inserting record.

I used GeneratedKeyHolder(class in spring) to get the auto id . The source is as below :

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(new PreparedStatementCreator()
    {
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException
        {
            PreparedStatement ps = con.prepareStatement(sql, new String[] { "id" });
            ps.setString(1, record.getCmdName());

            ps.setTimestamp(6, new Timestamp(System.currentTimeMillis()));                

            return ps;
        }
    }, keyHolder);        
    return keyHolder.getKey().intValue();

In the most environments, the code work well , but in one environment it throws exception as below. It's so surprising , and we failed to reproduce the exception in our testing environment.

INFO   | jvm 1    | 2013/09/24 11:03:47 | org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88; nested exception is java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88
INFO   | jvm 1    | 2013/09/24 11:03:47 | Caused by: 
INFO   | jvm 1    | 2013/09/24 11:03:47 | java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.jboss.resource.adapter.jdbc.WrappedConnection.lock(WrappedConnection.java:81)
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:345)
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at RecordDao$1.createPreparedStatement(RecordDao.java:60)
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:532)
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:771)
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at RecordDao.insertGongdan(RecordDao.java:56)
INFO   | jvm 1    | 2013/09/24 11:03:47 |      
INFO   | jvm 1    | 2013/09/24 11:03:47 |       at java.lang.Thread.run(Thread.java:722)
INFO   | jvm 1    | 2013/09/24 11:03:47 | 11:03:47,543 INFO  [TL1ServerSession] TL1ServerSession send!
INFO   | jvm 1    | 2013/09/24 11:03:47 | 11:03:47,543 INFO  [TL1ServerSession] Send TL1 Message: 
INFO   | jvm 1    | 2013/09/24 11:03:47 | 
4

4 回答 4

1

似乎您的“conn”对象未初始化,因此没有有效的连接来执行该语句。

于 2015-02-19T14:14:41.983 回答
1

您收到以下错误消息:

Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5

而你使用jdk 1.7. 但是并没有出现这个问题。

我开始在网上寻找这个问题并找到这个主题WhatDoesTheMessageDoYourOwnHousekeepingMean解释关闭连接对您意味着什么。

我认为您需要调整事务超时。@Ellie Fabrero:某些查询可能需要很长时间,因此达到超时并且休眠会引发异常。

于 2013-10-15T07:38:58.277 回答
0

我刚刚收到此错误,它看起来与当您没有有效的连接对象时执行查询有关。在我的例子中,我正在遍历一个列表并在列表的每个元素上调用一个插入,但是我的方法是以在调用第二个元素之前清理连接的方式编写的,因此出现了错误。

我想另一种情况是如上所述,连接对象根本没有初始化。

于 2015-04-20T14:38:43.113 回答
0

我对这条名为“未分类的 Sql 异常”的奇怪消息有同样的问题。

就我而言,我正在执行选择查询的表中有一些损坏的数据。这就是我们无法在其他环境中重现的原因,包括镜像数据库。

清理数据库表后,这个问题就解决了。

于 2017-11-07T16:36:25.453 回答