How to set JDBC connection timeout?

Discussion in 'Java' started by RC, Jul 23, 2003.

  1. RC

    RC Guest

    The Subject says its all.

    I can't do

    DriverManager dm = new DriverManager();

    But I can do

    Connection c = DriverManger.getConnection("jdbc:......", properties);

    My question is how do I use

    DriverManger.setLoginTimeout(10);

    to set the connection time out. If after 10 seconds still not
    able to connect to the database, then time out. throw to
    Exception
    By default if there is something wrong with the database server
    or the host. It may takes 30 seconds to catch in Exception.
    I want to shorter it to only 10 seconds. How do I do that?

    Thank Q very much in advance!
     
    RC, Jul 23, 2003
    #1
    1. Advertisements

  2. RC

    Sudsy Guest

    RC wrote:
    > The Subject says its all.
    >
    > I can't do
    >
    > DriverManager dm = new DriverManager();
    >
    > But I can do
    >
    > Connection c = DriverManger.getConnection("jdbc:......", properties);
    >
    > My question is how do I use
    >
    > DriverManger.setLoginTimeout(10);
    >
    > to set the connection time out. If after 10 seconds still not
    > able to connect to the database, then time out. throw to
    > Exception
    > By default if there is something wrong with the database server
    > or the host. It may takes 30 seconds to catch in Exception.
    > I want to shorter it to only 10 seconds. How do I do that?
    >
    > Thank Q very much in advance!
    >


    DriverManger.setLoginTimeout(10);
    Connection c = DriverManger.getConnection("jdbc:......", properties);
     
    Sudsy, Jul 23, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guoqi Zheng
    Replies:
    4
    Views:
    13,419
    Guoqi Zheng
    Jun 3, 2004
  2. Betty
    Replies:
    1
    Views:
    10,316
    Juha Laiho
    May 21, 2005
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,528
    robert
    Feb 11, 2006
  4. Bruce
    Replies:
    4
    Views:
    974
    Bjorn Abelli
    Mar 25, 2006
  5. Replies:
    4
    Views:
    10,884
  6. shmuel witman

    Connection timeout (connection closing after 100 sec )

    shmuel witman, Dec 4, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    1,680
    shmuel witman
    Dec 6, 2005
  7. tony
    Replies:
    1
    Views:
    366
    Manish Bafna
    Feb 28, 2007
  8. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,631
    Brian Candler
    Oct 6, 2004
Loading...