jiangboy
jiangboy

Reputation: 1

java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88

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 | 

Upvotes: 0

Views: 14802

Answers (4)

Rafael Moreira
Rafael Moreira

Reputation: 11

I had the same problem with this weird message called 'Uncategorized Sql Exception'.

In my case there were some corrupted data in the table that I was doing the select query. It was the reason we can't reproduce in other environment, including mirrored databases.

After cleaning the database table, this issue was solved.

Upvotes: 0

Cdn_Dev
Cdn_Dev

Reputation: 765

I was just getting this error and it looks like it has to do with executing a query when you don't have a valid connection object. In my case, I was looping through a list and calling an insert on each element of the list, but my method was written in a way that cleaned up the connection before the second element was called, thus the error.

I'd imagine the other case is as mentioned above, where the connection object isn't initialized at all.

Upvotes: 0

pazfernando
pazfernando

Reputation: 587

It seems that you "conn" object was not initialized so there is not a valid connection to execute the statement.

Upvotes: 1

herry
herry

Reputation: 1738

You get following error message:

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

and you used jdk 1.7. But it not occured this problem.

I start looking in net this problem and find this topic. WhatDoesTheMessageDoYourOwnHousekeepingMean explain the closing a connection what is mean for you.

I think you need to adjust the transaction timeout.@Ellie Fabrero say: Some of the query may take long so the timeout is reach and hibernate throws an exception.

Upvotes: 1

Related Questions