Results 1 to 12 of 12
  1. #1
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Thumbs down 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

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    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.

  3. #3
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Default

    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:

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    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.

  5. #5
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Default

    ok.. will check..

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    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?

  7. #7
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Default

    No,
    i'm not getting any exception/ error messages until i stop the code from running.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    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...

  9. #9
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Default

    yes.. it's hanging until i abort it

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    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.

  11. #11
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Default

    yes.. it's working..
    Thanks a lot..!!!

  12. #12
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Oh good.
    You can get rid of the "catch (Exception ex)" bit I suggested earlier now, since you don't need it.

Similar Threads

  1. Connection Error
    By meMalik in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 02-22-2010, 06:13 PM
  2. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  3. Connection timeout exception
    By wickedrahul9 in forum Advanced Java
    Replies: 2
    Last Post: 11-13-2008, 08:32 AM
  4. RAD - Error getting connection: Timeout.
    By ShoeNinja in forum Other IDEs
    Replies: 0
    Last Post: 09-09-2008, 05:25 PM
  5. Detect TimeOut in a HttpURL Connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •