3 Replies Latest reply: Dec 12, 2012 9:21 AM by Edward D.G. RSS

    Autoclose Database Conection.

    Edward D.G.
      I created this oracle conection:

      Context ctx = new InitialContext();
      DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/produccionDS");

      How can i set it for it close automatically in 20 second after it be uses it.?
        • 1. Re: Autoclose Database Conection.
          836548
          Edward D.G. wrote:
          I created this oracle conection:

          Context ctx = new InitialContext();
          DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/produccionDS");

          How can i set it for it close automatically in 20 second after it be uses it.?
          You can do so by setting maxIdle time for the datasource.
          • 2. Re: Autoclose Database Conection.
            gimbal2
            You'd have to schedule some parallel timed job to fire after 20 seconds and close the connection. I've never done that (its a bit of a questionable requirement if you ask me), so I can't say what will happen when you try to close a connection while there is a statement still running on it. You'll likely at least get an SQLException on the thread that is executing the statement.
            You can do so by setting maxIdle time for the datasource.
            That would work if the requirement is to close the connection when it is in fact idle; the OP made me think otherwise.
            • 3. Re: Autoclose Database Conection.
              Edward D.G.
              Can you write the example what do you say???