title: Java.sql.connection object is not working for second time
body: <p>I have declared Resource annotation in my program for the jboss application server. I am creating connection objects using these annotations. When i am using connection for first time it establishes connection and by using java.sql.ResultSetMetaData i am able to get values. But on second time i am getting exception as "java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@19adb". Why I am getting this exception.</p>
  
  <p>I am giving my jboss standalone.xml file and my java program as follows,</p>
  
  <p>standalone.xml:</p>
  
  <pre><code>&lt;datasources&gt;
                  &lt;datasource jndi-name="java:jboss/datasources/dcimpl" pool-name="dcimpl_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;
                          jdbc:mysql://localhost:3306/dcimpl?zeroDateTimeBehavior=convertToNull
                      &lt;/connection-url&gt;
                      &lt;driver&gt;
                          mysqldriver
                      &lt;/driver&gt;
                      &lt;transaction-isolation&gt;
                          TRANSACTION_READ_COMMITTED
                      &lt;/transaction-isolation&gt;
                      &lt;pool&gt;
                          &lt;min-pool-size&gt;
                              10
                          &lt;/min-pool-size&gt;
                          &lt;max-pool-size&gt;
                              50
                          &lt;/max-pool-size&gt;
                          &lt;prefill&gt;
                              true
                          &lt;/prefill&gt;
                          &lt;use-strict-min&gt;
                              false
                          &lt;/use-strict-min&gt;
                          &lt;flush-strategy&gt;
                              FailingConnectionOnly
                          &lt;/flush-strategy&gt;
                      &lt;/pool&gt;
                      &lt;security&gt;
                          &lt;user-name&gt;
                              root
                          &lt;/user-name&gt;
                          &lt;password&gt;
  
                          &lt;/password&gt;
                      &lt;/security&gt;
                      &lt;validation&gt;
                          &lt;validate-on-match&gt;
                              false
                          &lt;/validate-on-match&gt;
                          &lt;background-validation&gt;
                              false
                          &lt;/background-validation&gt;
                          &lt;useFastFail&gt;
                              false
                          &lt;/useFastFail&gt;
                      &lt;/validation&gt;
                      &lt;statement&gt;
                          &lt;prepared-statement-cache-size&gt;
                              100
                          &lt;/prepared-statement-cache-size&gt;
                          &lt;share-prepared-statements/&gt;
                      &lt;/statement&gt;
                  &lt;/datasource&gt;
                  &lt;datasource jndi-name="java:jboss/datasources/dcframework" pool-name="dcframework_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;
                          jdbc:mysql://localhost:3306/dcframework?zeroDateTimeBehavior=convertToNull
                      &lt;/connection-url&gt;
                      &lt;driver&gt;
                          mysqldriver
                      &lt;/driver&gt;
                      &lt;transaction-isolation&gt;
                          TRANSACTION_READ_COMMITTED
                      &lt;/transaction-isolation&gt;
                      &lt;pool&gt;
                          &lt;min-pool-size&gt;
                              10
                          &lt;/min-pool-size&gt;
                          &lt;max-pool-size&gt;
                              50
                          &lt;/max-pool-size&gt;
                          &lt;prefill&gt;
                              true
                          &lt;/prefill&gt;
                          &lt;use-strict-min&gt;
                              false
                          &lt;/use-strict-min&gt;
                          &lt;flush-strategy&gt;
                              FailingConnectionOnly
                          &lt;/flush-strategy&gt;
                      &lt;/pool&gt;
                      &lt;security&gt;
                          &lt;user-name&gt;
                              root
                          &lt;/user-name&gt;
                          &lt;password&gt;
  
                          &lt;/password&gt;
                      &lt;/security&gt;
                      &lt;validation&gt;
                          &lt;validate-on-match&gt;
                              false
                          &lt;/validate-on-match&gt;
                          &lt;background-validation&gt;
                              false
                          &lt;/background-validation&gt;
                          &lt;useFastFail&gt;
                              false
                          &lt;/useFastFail&gt;
                      &lt;/validation&gt;
                      &lt;statement&gt;
                          &lt;prepared-statement-cache-size&gt;
                              100
                          &lt;/prepared-statement-cache-size&gt;
                          &lt;share-prepared-statements/&gt;
                      &lt;/statement&gt;
                  &lt;/datasource&gt;
                  &lt;datasource jndi-name="java:jboss/datasources/dctest1" pool-name="dcframework_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;
                          jdbc:mysql://localhost:3306/dc_testing1?zeroDateTimeBehavior=convertToNull
                      &lt;/connection-url&gt;
                      &lt;driver&gt;
                          mysqldriver
                      &lt;/driver&gt;
                      &lt;transaction-isolation&gt;
                          TRANSACTION_READ_COMMITTED
                      &lt;/transaction-isolation&gt;
                      &lt;pool&gt;
                          &lt;min-pool-size&gt;
                              10
                          &lt;/min-pool-size&gt;
                          &lt;max-pool-size&gt;
                              50
                          &lt;/max-pool-size&gt;
                          &lt;prefill&gt;
                              true
                          &lt;/prefill&gt;
                          &lt;use-strict-min&gt;
                              false
                          &lt;/use-strict-min&gt;
                          &lt;flush-strategy&gt;
                              FailingConnectionOnly
                          &lt;/flush-strategy&gt;
                      &lt;/pool&gt;
                      &lt;security&gt;
                          &lt;user-name&gt;
                              root
                          &lt;/user-name&gt;
                          &lt;password&gt;
  
                          &lt;/password&gt;
                      &lt;/security&gt;
                      &lt;validation&gt;
                          &lt;validate-on-match&gt;
                              false
                          &lt;/validate-on-match&gt;
                          &lt;background-validation&gt;
                              false
                          &lt;/background-validation&gt;
                          &lt;useFastFail&gt;
                              false
                          &lt;/useFastFail&gt;
                      &lt;/validation&gt;
                      &lt;statement&gt;
                          &lt;prepared-statement-cache-size&gt;
                              100
                          &lt;/prepared-statement-cache-size&gt;
                          &lt;share-prepared-statements/&gt;
                      &lt;/statement&gt;
                  &lt;/datasource&gt;
                  &lt;datasource jndi-name="java:jboss/datasources/dctest2" pool-name="dcframework_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;
                          jdbc:mysql://localhost:3306/dc_testing2?zeroDateTimeBehavior=convertToNull
                      &lt;/connection-url&gt;
                      &lt;driver&gt;
                          mysqldriver
                      &lt;/driver&gt;
                      &lt;transaction-isolation&gt;
                          TRANSACTION_READ_COMMITTED
                      &lt;/transaction-isolation&gt;
                      &lt;pool&gt;
                          &lt;min-pool-size&gt;
                              10
                          &lt;/min-pool-size&gt;
                          &lt;max-pool-size&gt;
                              50
                          &lt;/max-pool-size&gt;
                          &lt;prefill&gt;
                              true
                          &lt;/prefill&gt;
                          &lt;use-strict-min&gt;
                              false
                          &lt;/use-strict-min&gt;
                          &lt;flush-strategy&gt;
                              FailingConnectionOnly
                          &lt;/flush-strategy&gt;
                      &lt;/pool&gt;
                      &lt;security&gt;
                          &lt;user-name&gt;
                              root
                          &lt;/user-name&gt;
                          &lt;password&gt;
  
                          &lt;/password&gt;
                      &lt;/security&gt;
                      &lt;validation&gt;
                          &lt;validate-on-match&gt;
                              false
                          &lt;/validate-on-match&gt;
                          &lt;background-validation&gt;
                              false
                          &lt;/background-validation&gt;
                          &lt;useFastFail&gt;
                              false
                          &lt;/useFastFail&gt;
                      &lt;/validation&gt;
                      &lt;statement&gt;
                          &lt;prepared-statement-cache-size&gt;
                              100
                          &lt;/prepared-statement-cache-size&gt;
                          &lt;share-prepared-statements/&gt;
                      &lt;/statement&gt;
                  &lt;/datasource&gt;
                  &lt;datasource jndi-name="java:jboss/datasources/dctest3" pool-name="dcframework_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;
                          jdbc:mysql://localhost:3306/dc_testing3?zeroDateTimeBehavior=convertToNull
                      &lt;/connection-url&gt;
                      &lt;driver&gt;
                          mysqldriver
                      &lt;/driver&gt;
                      &lt;transaction-isolation&gt;
                          TRANSACTION_READ_COMMITTED
                      &lt;/transaction-isolation&gt;
                      &lt;pool&gt;
                          &lt;min-pool-size&gt;
                              10
                          &lt;/min-pool-size&gt;
                          &lt;max-pool-size&gt;
                              50
                          &lt;/max-pool-size&gt;
                          &lt;prefill&gt;
                              true
                          &lt;/prefill&gt;
                          &lt;use-strict-min&gt;
                              false
                          &lt;/use-strict-min&gt;
                          &lt;flush-strategy&gt;
                              FailingConnectionOnly
                          &lt;/flush-strategy&gt;
                      &lt;/pool&gt;
                      &lt;security&gt;
                          &lt;user-name&gt;
                              root
                          &lt;/user-name&gt;
                          &lt;password&gt;
  
                          &lt;/password&gt;
                      &lt;/security&gt;
                      &lt;validation&gt;
                          &lt;validate-on-match&gt;
                              false
                          &lt;/validate-on-match&gt;
                          &lt;background-validation&gt;
                              false
                          &lt;/background-validation&gt;
                          &lt;useFastFail&gt;
                              false
                          &lt;/useFastFail&gt;
                      &lt;/validation&gt;
                      &lt;statement&gt;
                          &lt;prepared-statement-cache-size&gt;
                              100
                          &lt;/prepared-statement-cache-size&gt;
                          &lt;share-prepared-statements/&gt;
                      &lt;/statement&gt;
                  &lt;/datasource&gt;
                  &lt;drivers&gt;
                      &lt;driver name="h2" module="com.h2database.h2"&gt;
                          &lt;xa-datasource-class&gt;
                              org.h2.jdbcx.JdbcDataSource
                          &lt;/xa-datasource-class&gt;
                      &lt;/driver&gt;
                      &lt;driver name="postgresql" module="org.postgresql"&gt;
                          &lt;xa-datasource-class&gt;
                              org.postgresql.xa.PGXADataSource
                          &lt;/xa-datasource-class&gt;
                      &lt;/driver&gt;
                      &lt;driver name="mysqldriver" module="com.mysql"/&gt;
                  &lt;/drivers&gt;
              &lt;/datasources&gt;
  </code></pre>
  
  <p>My java program :</p>
  
  <pre><code>@Stateless
  public class DispalyConfigScreenBO {
      HashMap&lt;String, Connection&gt; memoryConn = new HashMap&lt;String, Connection&gt;();
  
      @Resource(mappedName = "java:jboss/datasources/dctest1")
      DataSource dataSource1;
  
      @Resource(mappedName = "java:jboss/datasources/dctest2")
      DataSource dataSource2;
  
      @Resource(mappedName = "java:jboss/datasources/dctest3")
      DataSource dataSource3;
  
    public String createPoolConns() {
  
          try {
              Connection con1 = dataSource1.getConnection();
              memoryConn.put("dctest1", con1);
  
              Connection con2 = dataSource2.getConnection();
              memoryConn.put("dctest2", con2);
  
              Connection con3 = dataSource3.getConnection();
              memoryConn.put("dctest3", con3);
          } catch (Exception e) {
              System.out.println("Exception in createPoolConns = " + e);
          }
          return "success";
      }
  
  
  public String parseColumnnames(String value, String datasource)
              throws Exception {
          StringBuilder output = new StringBuilder();
          Connection conn = null;
          Statement st = null;
          ResultSet rs = null;
          try {
  
              conn = memoryConn.get(datasource);
              if (conn == null) {
                  return null;
              } else {
  
                  st = conn.createStatement();
                  rs = st.executeQuery((value + " LIMIT 1").replace(";", ""));
                  ResultSetMetaData rsMetaData = rs.getMetaData();
                  int numberOfColumns = rsMetaData.getColumnCount();
                  for (int i = 1; i &lt;= numberOfColumns; i++) {
  
                      if (i == numberOfColumns) {
                          output.append(rsMetaData.getColumnLabel(i));
                      } else {
                          output.append(rsMetaData.getColumnLabel(i));
                          output.append(",");
                      }
                  }
              }
          } catch (Exception dbException) {
              dbException.printStackTrace();
          } finally {
              if (rs != null) {
                  rs.close();
              }
              if (st != null) {
                  st.close();
              }
              if (conn != null) {
                  conn.close();
              }
          }
          return output.toString();
      }
  </code></pre>
  
  <p>I am creating hashmap and put all the connection objects in that hashmap and using that hashmap where ever neccessary to get connection objects. But is not working except for first time.</p>
  
  <p>Help me.</p>