Forum Stats

  • 3,838,282 Users
  • 2,262,351 Discussions
  • 7,900,575 Comments

Discussions

Autoclose Database Conection.

Edward D.G.
Edward D.G. Member Posts: 167
edited Dec 12, 2012 2:01PM in JDeveloper and ADF
I created this oracle conection for call Ireport's repots:

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

How can i set it for it close automatically in 20 second after it be uses it?

Best Answer

  • EonvanTonder
    EonvanTonder Member Posts: 89
    Answer ✓
    You should close connections when you are done with them, try this
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myConnectionDS");
    Connection conn = ds.getConnection();
    
    //call the report
    
    conn.close(); //this will release the connection back to the pool
    Of course, the connection will still remain open after it is returned to the pool so an option would be to set your initial pool size to 0, enable pool shrinking and set the shrink frequency to 20 seconds

Answers

  • Edward D.G.
    Edward D.G. Member Posts: 167
    No body can help me???
  • EonvanTonder
    EonvanTonder Member Posts: 89
    Answer ✓
    You should close connections when you are done with them, try this
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myConnectionDS");
    Connection conn = ds.getConnection();
    
    //call the report
    
    conn.close(); //this will release the connection back to the pool
    Of course, the connection will still remain open after it is returned to the pool so an option would be to set your initial pool size to 0, enable pool shrinking and set the shrink frequency to 20 seconds
This discussion has been closed.