[jboss-user] [JCA/JBoss] - Re: Problem of accessing Oracle DS in JBOSS from a stand-alo

weston.price@jboss.com do-not-reply at jboss.com
Wed Apr 18 08:57:03 EDT 2007


One more 'anti-pattern', actually, it's a bug IMO. When using the Remote data source code like the following can lead to a leak pretty quickly:


  | 
  | try
  | {
  |   Connection conn = DataSource.getConnection()
  |   PreparedStatement ps = conn.prepareCall("SomeSQL");
  |   ps.close();
  | 
  | }catch(Exception e)
  | {
  | 
  | }
  | finally
  | {
  |   
  |    if(ps != null)
  |      ps.close();
  | 
  |    if(conn != null)
  |      conn.close();
  | 
  | }
  | 

What ends up happening in this particular instance is that the first ps.close() actually removes the Statement from the internal map on the server side. At the second close attempt a SQLException is thrown (who knows why). As a result, the connection itself would never get closed in this case. This actually crept up on the TCK for Oracle10g and was causing all sorts of issues.

Yes, I know that to be 'truly' safe both the ps.close() and the conn.close() should be contained within their own try/catch/finally block but this is never a guarantee.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4038366#4038366

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4038366



More information about the jboss-user mailing list