Results 1 to 6 of 6
  1. #1
    ko_aung is offline Member
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    6
    Rep Power
    0

    Question interrupt a jdbc connection thread

    Hi,

    I have a program which spawn a thread connecting to DB.

    Java Code:
    // load jdbc driver
    // declare varialbles
    Connection con = DriverManager.getConnection(url);
    When the DB or network is down and cannot open the connection, it hangs there.

    I tried to call Thread.interrupt() from parent but it seems like it's waiting for the connection to finish.

    Is there a way to interrupt the JDBC connection in a thread?

    Regards,

    ko_aung

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Try DriverManager.setLoginTimeout () before calling getConnection() ?

  3. #3
    ko_aung is offline Member
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    6
    Rep Power
    0

    Default not working for jdbc2.1 and db2 v8

    hi iluxa,

    thanks. i've tried it. i forgot to mention that the environment i'm working on is DB2 v8 and JDBC 2.1.

    DB2 v8 doesn't support DriverManager.setLoginTimeout() from JDBC 2.1 Core API. it has no effect.

    Methods, Data Types, and Features That Are Not Supported by DB2 JDBC Drivers

    that's why i need to find a way to interrupt the connection explicitly, and i'm also curious how to interrupt a thread if similar cases happen.

    the method you mentioned works for DB2 v9 with JDBC 3.0.

    thanks.

    regards,
    ko_aung

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    great...

    another "attempt" would be like getConnection (url, properties), see DB2 Universal Database for the various properties... seems to have a login timeout... who knows maybe it'll work all of a sudden

  5. #5
    ko_aung is offline Member
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    6
    Rep Power
    0

    Default

    yeah.. maybe it'll work. i didn't have a chance to try it out.
    as luck would have it, the db2 version will be upgraded to v9.1 and so i'm able to upgrade my jdk and jdbc version also.

    using jdbc 3.0 with db2 v9.1 now and session timeout thing is working.

    anyway, my main concern about posting in this category is that whether is there a way to interrupt a thread in this kind of situation. any idea?

    thanks.

    regards,
    ko_aung

  6. #6
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    The only way to do that I am aware about is Thread.interrupt ()... which you have tried already... I think you're stuck :D

Similar Threads

  1. JDBC DataBase Connection
    By sh4dyPT in forum New To Java
    Replies: 1
    Last Post: 04-06-2010, 03:13 AM
  2. JDBC connection
    By evermore in forum JDBC
    Replies: 1
    Last Post: 03-19-2010, 09:35 AM
  3. JDBC Connection...
    By onlysumitg in forum JDBC
    Replies: 3
    Last Post: 08-21-2009, 12:34 PM
  4. JDBC connection
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-10-2007, 08:39 PM
  5. How to close JDBC Connection
    By Heather in forum JDBC
    Replies: 2
    Last Post: 07-15-2007, 02:07 PM

Tags for this Thread

Posting Permissions

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