permaculture playing cards*
The moose likes JDBC and the fly likes How Stealed connection will exists? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How Stealed connection will exists?" Watch "How Stealed connection will exists?" New topic
Author

How Stealed connection will exists?

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Dear All

As we heard stealed connection's exists because of improper closing of connection in the application. so why cant we use static variables for Connection,ResultSet,Statement and close them using finalize method in my appllication instead of closing the connection in all the methods is it eliminates the stealed connection


Creativity is nothing but Breaking Rules
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Sorry for the previous post

Its stale Connections
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

Santosh,
A stale connection is caused by a timeout with the database. Making a connection a static variable increases the chance of a stale connection. Since the static variable lives for the life of the program, odds are that connection will experience a timeout sooner or later.


[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
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296

Making a connection a static variable increases the chance of a stale connection. Since the static variable lives for the life of the program


Is it possible to eliminate the stale connections by making declaring the connection object inside the method (Not declaring as static out side)
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
It is not possible to eliminate stale connections. As Jeanne said, it is caused by a timeout with the DB- and we cannot control that timeout as it is configured at the DB level.

It's best to handle stale connections effectively in your code and get a new connection in case you get one.


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Stealed connection will exists?