java.sql.SQLException:Connection与托管connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88无关联

时间:2013-10-15 06:31:46

标签: mysql jboss

我正在使用jboss5.1和spring作为系统的架构。 mysql的版本为5.6.12jdk的版本为1.7。 场景:因为我需要更新系统不久之前插入DB的记录,
我尝试在执行插入记录时获取记录的id。

我使用GeneratedKeyHolder(春天的课程)来获取自动ID。来源如下:

    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();

在大多数环境中,代码运行良好,但在一个环境中,它会抛出异常,如下所示。这是如此令人惊讶,我们未能在我们的测试环境中重现异常。

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 个答案:

答案 0 :(得分:1)

您收到以下错误消息:

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

您使用了jdk 1.7。但它没有出现这个问题。

我开始在网上查找此问题并找到this topicWhatDoesTheMessageDoYourOwnHousekeepingMean解释关闭连接对你意味着什么。

我认为你需要调整事务超时。@ Ellie Fabrero say:一些查询可能需要很长时间才能达到超时,而hibernate会抛出异常。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

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

我想其他情况如上所述,连接对象根本没有初始化。

答案 3 :(得分:0)

我对这个名为' Uncategorized Sql Exception'的奇怪消息也有同样的问题。

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

清理数据库表后,此问题已解决。