• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Connection configuration

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rafael Quintana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rafael,

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

Cheers,
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic