When you get the connection you will need to put it in a try and catch.
At the end use a finally to return the connection.
e.g.

try
{
        Connection c = YourClass.getConnection();
}
catch (SQLException ex)
{
        //Do something with the exception
}
finally
{
        YourClass.returnJDBCConnection(c);
}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Ian S. Hagen
Sent: 11 September 2001 08:21
To: Orion-Interest
Subject: OC4J datasource / server crash problem


Hi,

I am currently part of a project developing a servlet/stateless EJB
solution to be run on the Orion platform.  We are experiencing some
problems using our datasource connection to our Oracle 9i database.  The
server will on occasion leak connections, which eventually results in
both the Orion server and the database crashing.  

I include our data-sources.xml file to indicate how things are set up.
We currently only use the ejb-location for database access from our EJBs
and servlets. 



<?xml version="1.0"?>
<!DOCTYPE data-sources PUBLIC "Orion data-sources"
"http://xmlns.oracle.com/ias/dtds/data-sources.dtd";>

<data-sources>

  <!-- Setting up the data source for the zellsoft provider -->
        <data-source
                class="com.evermind.sql.DriverManagerDataSource"
                name="zellsoft"
                location="jdbc/zellsoft"
                xa-location="jdbc/xa/zellsoft"
                ejb-location="jdbc/ejb/zellsoft"
                        pooled-location="jdbc/pool/zellsoft"
                connection-driver="oracle.jdbc.driver.OracleDriver"
                url="jdbc:oracle:thin:@oracle.zellsoft.com:1521:UTF"
                username="zs"
                password="zs"
                max-connections="20"
                min-connections="5"
                max-connect-attempts="10"
                connection-retry-interval="1"
                inactivity-timeout="30"
                wait-timeout="30"
        />

</data-sources>



Our code for retrieval of the database connection:

  private static Connection getConnection( String provider, String
prefix )
    throws InitializerException {

    try {

      if (ic==null) ic = new InitialContext();

      DataSource ds = (DataSource) ic.lookup(prefix+provider);

      Connection conn = ds.getConnection();

      conn.setAutoCommit(false);
      return conn;

    } catch (NamingException cfe) {
      throw new InitializerException("Unable to lookup Datasource" );
    } catch (SQLException se) {
      throw new InitializerException("Unable to get DB connection");
    }
  }



Returning the connection:

  public static void returnJDBCConnection(Connection conn)
    throws InitializerException {

    try {
      conn.close();
    } catch (SQLException se) {
      throw new InitializerException("Unable to return DB connection");
    }
  }



The exception we are getting is:

OrionCMTConnection not closed, check your code!
LogicalDriverManagerXAConnection not closed, check your code!
Created at:
java.lang.Throwable: OrionCMTConnection created
        at
com.evermind.sql.OrionCMTConnection.<init>(OrionCMTConnection.java:39)
        at
com.evermind.sql.OrionCMTDataSource.getConnection(OrionCMTDataSource.jav
a:56)
        at
com.zellsoft.services.dbconnection.Initializer.getConnection(Initializer
.java:79)
        at
com.zellsoft.services.dbconnection.Initializer.getJDBCConnection(Initial
izer.java:46)
        at
com.zellsoft.session.SessionManagerEJBBean.logOnAdmUser(SessionManagerEJ
BBean.java:1276)
        at
com.zellsoft.session.SessionManagerEJBBean.logOnUser(SessionManagerEJBBe
an.java:1250)
        at
com.zellsoft.session.SessionManagerEJBBean.executeCmd(SessionManagerEJBB
ean.java:475)
        at
SessionManagerEJB_StatelessSessionBeanWrapper0.executeCmd(SessionManager
EJB_StatelessSessionBeanWrapper0.java:71)
        at com.zellsoft.media.web.adm.AmmWeb.doPost(AmmWeb.java:157)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:211)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:309)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
        at
com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestD
ispatcher.java:508)
        at
com.evermind.server.http.ServletRequestDispatcher.forwardInternal(Servle
tRequestDispatcher.java:177)
        at
com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHa
ndler.java:576)
        at
com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:
189)
        at
com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:62)


I have experiemented using the
oracle.jdbc.pool.OracleConnectionPoolDataSource, but is appears to cause
connections to be leaked at an even higher rate.

Environment:
        Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
        SuSE Linux



Can you say if we are doing anything wrong?  I have inspected the code,
and cannot find anywhere where connections are never returned.  All our
JDBC is within try-catch-finally blocks where returning the connection
is done in the finally block.

Any ideas?

        Ian


Reply via email to