Results 1 to 12 of 12
- 09-09-2010, 08:40 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
capture db connection timeout error
Hi,
I recently got an error from one of my java application that when the application tried to connect to the DB it doesn't write any exception if it is a timeout error. Can someone help me how to capture this error and write it down to a log file so that we can find the error for the first time by referring the log file.
Thanks,
Uthpala
- 09-09-2010, 08:54 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
How are you getting connections?
What try/catch blocks do you have?
What driver are you using, because I'm pretty sure all the ones I've used will throw a SQLException on a timeout.
- 09-09-2010, 09:45 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
Java Code:package JavaApplication8; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author uthpalaw */ public class CheckDBConn { public static void main(String arg[]){ try { Connection con = null; Class.forName("oracle.jdbc.OracleDriver"); // Load (and therefore register) the Oracle Driver con = DriverManager.getConnection("jdbc:oracle:thin:@ip:1521:SID", "userid", "password"); // Get a Connection to the database // @machineName:port:SID, userid, password System.out.println("DB Connected"); } catch (SQLException ex) { Logger.getLogger(CheckDBConn.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(CheckDBConn.class.getName()).log(Level.SEVERE, null, ex); } } }
this is the whole code i used . There i have captured both SQL and ClassNotFoundException, but those both are unable to capture the timeout error.:confused:
- 09-09-2010, 09:58 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
So you're getting "DB Connected" being printed out?
If not, add "catch (Exception ex) { ...log it.. }" at the end of the catches and see what's happening.
- 09-09-2010, 10:07 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
ok.. will check..
- 09-09-2010, 10:17 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
I'm guessig from that "Db Connected" is not being printed out.
In which case what's happening?
What exception do you get when you run this?
You must be seeing something?
- 09-09-2010, 10:46 AM #7
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
No,
i'm not getting any exception/ error messages until i stop the code from running.
- 09-09-2010, 10:53 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
So that code up there is hanging?
That's not what you implied in your OP.
If it's hanging then it's not timing out...
- 09-09-2010, 11:09 AM #9
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
yes.. it's hanging until i abort it
- 09-09-2010, 11:13 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
In which case the driver timeout needs to be set, though I thought it was defaulted.
Try setting the login timeout to 10 seconds (or less).
If it's taking that long to login I suspect something's up somewhere.
- 09-09-2010, 11:35 AM #11
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
yes.. it's working..
Thanks a lot..!!!
- 09-09-2010, 11:45 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Connection Error
By meMalik in forum JavaServer Faces (JSF)Replies: 1Last Post: 02-22-2010, 06:13 PM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Connection timeout exception
By wickedrahul9 in forum Advanced JavaReplies: 2Last Post: 11-13-2008, 08:32 AM -
RAD - Error getting connection: Timeout.
By ShoeNinja in forum Other IDEsReplies: 0Last Post: 09-09-2008, 05:25 PM -
Detect TimeOut in a HttpURL Connection
By Ed in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 04:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks