wood burning stoves 2.0*
The moose likes JDBC and the fly likes TOO MANY CONNCTIONS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "TOO MANY CONNCTIONS" Watch "TOO MANY CONNCTIONS" New topic
Author

TOO MANY CONNCTIONS

Sanjay Rawat
Greenhorn

Joined: Feb 27, 2009
Posts: 8
Hi friends

Iam getting an exception as "too many connection" by db after hitting db 10-20 times.
it works well in 10-20 hits to db but after that i got this error
is there anyother way to close the connection?,if i dont want to close the connection in my each jsp page.?.
my context.xml entry is like this
i set maxActive=30
maxidle=10
removeabondoned=true
removeabondonedtimeout=20
..
.
.
.
.

please help i dont want to close the connection in my each JSP page...
is there anyother way provided by APACHE to close the connetion and get the objects back in pool.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Sanjay,
First of all, you shouldn't be using the Connection in any JSP page. The JSP is for rendering the view. All JDBC code should be in a Java class.

Second, you have to close the connection everyplace you use it. Whether that is a JSP or Java class it is the same thing. Every place that obtains a connection is responsible for closing it. Anything else is a connection leak.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sanjay Rawat
Greenhorn

Joined: Feb 27, 2009
Posts: 8
ok i will definitely pay attention on your word ,, But my question that ,i m using connection pool by apache and is there any way to close the connection without using conn.close() in every where..is there any functionality provide by apache.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No. JDBC connections will eventually time out but you should not be relying on this. It's bad practice not to call close() in a finally block.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: TOO MANY CONNCTIONS
 
Similar Threads
Database Access Design
Session Variables and DB access...
Not using beans, sessions possible anyway?
Forcibly closing an http connection
Can we execute two sql statements with one Connection object?