Results 1 to 8 of 8
Thread: Keep database connection alive
- 06-26-2011, 10:36 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
Keep database connection alive
I'm developing a windows desktop (standalone) application which runs as an endless loop.
Once the application started, a database connection is created (java.sql.Connection) and from now on used to read data from the database.
Connection is created like this:
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
Connection con = DriverManager.getConnection(connectionUrl);
Does the connection will be kept alive forever?
If NOT, what to change in my program?Last edited by major; 06-26-2011 at 01:44 PM.
- 06-27-2011, 09:02 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Depends on what scope you are opening the connection in and how long you leave it idle.
- 06-27-2011, 09:48 AM #3
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
By the way: My application is the only one to use this connection and perform step by step actions (sql queries). No use of threads.
I would like to know what to do in both cases:
1.connection needs to stay always opened
2.connection is left idle for 15 minutes.
- 06-27-2011, 09:50 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
1. Uhm, save the connection in a static context and open it only once, maybe (Edit: and a shutdown hook to close it properly, as well)?
2. Well, what are the "session/connection timeout" settings for the DB in question?
- 06-27-2011, 10:12 AM #5
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
2. no session/connection timeout (should I define this?).
My program perform IO operations and web service calls also. so this operations may take additional time and meanwhile the connection is idle
- 06-27-2011, 11:11 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Since you'll have to handle the situation of a disconnect you may as well consider dealing with that from the start.
- 06-27-2011, 11:48 AM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 06-29-2011, 09:21 AM #8
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
connection to database
By manojkumarsahu in forum New To JavaReplies: 1Last Post: 08-06-2010, 09:26 PM -
getting database connection
By ravidasineni in forum AWT / SwingReplies: 0Last Post: 11-27-2009, 04:33 AM -
getting database connection
By ravidasineni in forum AWT / SwingReplies: 1Last Post: 11-22-2009, 02:01 AM -
Keep my TCP connection alive
By eggmanpete in forum Advanced JavaReplies: 4Last Post: 03-02-2009, 06:11 AM -
Database Connection
By vipinkumarsolanki in forum Advanced JavaReplies: 2Last Post: 11-26-2007, 06:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks