GeeCON Prague 2014*
The moose likes JDBC and the fly likes JDBC Connection configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection configuration" Watch "JDBC Connection configuration" New topic
Author

JDBC Connection configuration

Rafael Quintana
Greenhorn

Joined: Oct 10, 2005
Posts: 6
Hi everybody.
I'm having troubles in find the correct way to close my database connection.

I'm using JDCB and access an iseries:

//...
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
Connection micon=DriverManager.getConnection("jdbc:as400://IASO1333;naming=system",
application.getInitParameter(ambiente+"iSeriesUser"),
application.getInitParameter(ambiente+"iSeriesPassword"));
//...

The problem is the idle connections are mantained for about 2 hours!!, i've looking on the iseries server documentation with no results, aslo i looked for the setTimeout() method on the java.sql.Connection class without success.

Please help me these idle-and-still-open connections are laughing on me!

PD

I know the connectionpool is a better aproach to manage connections, but this time is a programmer-pride issue
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Rafael,
Welcome to JavaRanch!

I might be missing the point here, but why don't you just close the connection (in a finally block) when you are done with it. Then it won't be idle.


[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
Rafael Quintana
Greenhorn

Joined: Oct 10, 2005
Posts: 6
Thanks so much for your reply.

I've decided to keep the connection open on the same session as it allows me a better control on the database server: on the as/400 the database service which listens on 8471 port, generates a new job for each new connection; that's why i keep the connection alive along the same session.


Thanks again.
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Rafael,

If you want to keep the connection open across multiple applications, look into connection pooling. Apache has a great .API for this.

Cheers,


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Rafael,
I know the connectionpool is a better aproach to manage connections

I think you know the answer. Keeping sessions open for long periods of time is dangerous and doesn't scale well. Either way, you really do need a connection pool. Otherwise, you are trading pride for all sorts of undesirable side effects.
Rafael Quintana
Greenhorn

Joined: Oct 10, 2005
Posts: 6
Ok Thanks for the light!

I'll try with connectionPool.

Though i'm still unsatisfied as i was not able to find the setTimeout() method on the Connection class.

Thanks to everybody.
Fernando Lescano
Greenhorn

Joined: Oct 21, 2005
Posts: 1
Hi my friends.. I`m having the same problems, the idle conections to 8471 port in the as400 server are mantained opened for at least 2 hours, even when I used connection.closed(); method to kill them. I�m also using ResultSet object to obtain all the results of my queries.
Each new connection generates a new job which expends server memory and making the as400 slower and slower, as new connections are created.
My question is.. is there any solution to close them without waiting this time?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JDBC Connection configuration