This discussion is archived
3 Replies Latest reply: Dec 12, 2012 7:21 AM by Edward D.G. RSS

Autoclose Database Conection.

Edward D.G. Newbie
Currently Being Moderated
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 Journeyer
    Currently Being Moderated
    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 Guru
    Currently Being Moderated
    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. Newbie
    Currently Being Moderated
    Can you write the example what do you say???

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points