0 Replies Latest reply on Jan 26, 2008 3:41 PM by KrazyK

    JNDI Prblem

    KrazyK
      Hello, I have a JNDI datasource set up in the jrun-resources.xml file and I am using this simple class to access it and test a simple prepared statement. For some reason, this connection is not closing. I have made a coldfusion page and accessed this class and it keeps the connection open and shows up in Oracle as an inactive connection. Eventually we run out of connections and the database stops responding. We have a large java backend for our application and would like to use JNDI for the connection pooling. Can anyone tell my how to make the connections close??? A standard JDBC connection closes fine just not a JRUN JDNI managed connection.

      Here is the jrun resources entry.

      <data-source>
      <dbname>ECP</dbname>
      <driver>oracle.jdbc.driver.OracleDriver</driver>
      <url>jdbc:oracle:thin:@liworadev:121:liwdev</url>
      <username>ECP00666</username>
      <password>changeme</password>
      <encrypted>false</encrypted>
      <!--<encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class> -->
      <native-results>false</native-results>
      <remove-on-exceptions>true</remove-on-exceptions>
      <pool-statements>true</pool-statements>
      <initial-connections>20</initial-connections>
      <connection-timeout>5</connection-timeout>
      <transaction-timeout>20</transaction-timeout>
      <cache-enabled>true</cache-enabled>
      <cache-size>5</cache-size>
      <cache-refresh-interval>10</cache-refresh-interval>
      <jndi-name>ECP</jndi-name>
      <poolname>ECP</poolname>
      <minimum-size>5</minimum-size>
      <maximum-size>10</maximum-size>
      <user-timeout>20</user-timeout>
      <skimmer-frequency>15</skimmer-frequency>
      <shrink-by>30</shrink-by>
      <maximum-soft>true</maximum-soft>
      <debugging>true</debugging>
      <disable-pooling>false</disable-pooling>
      <isolation-level>READ_COMMITTED</isolation-level>
      <description>SelectMethod=cursor</description>
      </data-source>


      Here is the class.

      public class TestJNDI {

      private String JNDIDatasourceName;

      public TestJNDI (String JNDIDatasource) {

      this.JNDIDatasourceName = JNDIDatasource;
      }


      /**
      This is a test to see if a jrun managed connection is being closed

      */

      public boolean Test() throws Exception {
      Connection connection = null;

      System.out.println("Looky here datasoure" + JNDIDatasourceName);
      jrun.sql.JRunConnectionHandle jCon = null;
      Context initialContext;
      javax.sql.DataSource ds = null;
      try
      {
      System.out.println("about to create initialContext");
      System.out.println(JNDIDatasourceName);
      initialContext= new InitialContext();
      System.out.println("about to get datasource");
      ds = (javax.sql.DataSource) initialContext.lookup (JNDIDatasourceName);
      }
      catch (NamingException e)
      {
      System.out.println("Cannot create InitialContext" + e);
      }

      try
      {
      //connection = jCon;
      //connection.setAutoCommit(false);
      System.out.println("about to get jcon");
      System.out.println("ds.getConnection() = " + ds.getConnection().getClass().getName());

      jCon = (jrun.sql.JRunConnectionHandle) ds.getConnection();


      // jCon = (jrun.sql.JRunConnectionHandle) ds.getConnection();
      // connection = ds.getConnection();
      // System.out.println("jCon = " + jCon.getClass().getName());
      connection = jCon.getPhysicalConnection();

      connection.setAutoCommit(false);

      System.out.println("connection = " + connection.getClass().getName());

      PreparedStatement statement = connection.prepareCall("Select sysdate from dual");

      System.out.println("executing select from dual");

      System.out.print( statement.execute() );

      System.out.println("select from dual complete");

      statement.close();

      connection.close();

      jCon.close();

      }

      catch ( ClassCastException e)
      {
      System.out.println("a class cast has occured");
      e.printStackTrace();
      }
      catch ( Exception e)
      {

      e.printStackTrace();
      }

      boolean booConn = connection.isClosed();

      System.out.println("connection " + booConn );

      return booConn;
      }
      }