Problem with statements in WebLogic


EJB programming & troubleshooting: Problem with statements in WebLogic

  1. Problem with statements in WebLogic (3 messages)


      We are facing a tyipcal problem with closing of statements in weblogic
       Generally we create statement in try block of the method
       and closes in finally block. But if a particualr method is invoked and by the time it reaches finally block, if 2 or more invokes happen simultaneously on that method, then
    the statements are not closing(assuming its not reaching finally block). To avoid this we have closed the statement in try block also to avoid open statement problem. It means same code we have written before end of try block(after the usage of statement) and in finally block which is not good practise but no alternative

       There is no problem with websphere and jboss only facing the problem with weblogic
       Do let us know any remedy is there for this

    B S Reddy
  2. Waiting for the Reply Pls

    B S Reddy
  3. Hi

    try like this

    package example;
    import java.sql.*;
    import javax.naming.*;
    import javax.sql.*;

    public class StatementExample {
      public StatementExample() {
        Context ctx = null;
        DataSource ds = null;
        Connection conn = null;
        Statement stat = null;
        ResultSet rs = null;
        try {
          ctx = new InitialContext();
          ds = (DataSource) ctx.lookup ("datasources/NonTxDataSource");
          conn = ds.getConnection();
          stat = conn.createStatement();
          rs = stat.executeQuery("SELECT * FROM DUAL");
        catch (NamingException ex) {
        catch (SQLException ex) {
        finally {
          if (rs != null) {
            try { rs.close(); } catch (SQLException ex) { ex.printStackTrace();}
          if (stat != null) {
            try { stat.close(); } catch (SQLException ex) { ex.printStackTrace();}
          if (conn != null) {
            try { conn.close(); } catch (SQLException ex) { ex.printStackTrace();}
          if (ctx != null) {
            try { ctx.close(); } catch (NamingException ex) { ex.printStackTrace();}

    Best regards, Stefano
  4. Hi ,
        Try this...

    { try
    if (statement!= null) {
    if(connection != null && ! connection.isClosed())
    catch (Exception exceptionFinally)
    throw your application exception;
    I don;t think that the problem statement you have written is the real cause. The finally block will always be executed. Catch the exception and may be you can paste the stack trace here .

    Hope that helps.