File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes  DriverManager.getConnection hangs from actionPerformed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark " DriverManager.getConnection hangs from actionPerformed" Watch " DriverManager.getConnection hangs from actionPerformed" New topic

DriverManager.getConnection hangs from actionPerformed

faisal hameed
Ranch Hand

Joined: Jan 19, 2009
Posts: 48
I am using oracle 11g and jdk 1.6 and ojdbc6 driver.
I have created GUI in netbeans GUI builder with DND.
I want to make a db connection from JButton actionPerformed method but it hangs on DriverManager.getConnection().
what is wrong with the following code.I have called this method from actionPerformed DataBase.createConnection1().

Regards, M Faisal Hameed
PUCIT, Pakistan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10825

The problem is with your swing code. You should put your DB code on a separate thread.
Recommended reading

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
faisal hameed
Ranch Hand

Joined: Jan 19, 2009
Posts: 48
Thanks for reply.
I have tried this code on 10 different PC's on same environment but it creates problem on only 2,3 PC's and hangs.
If it is my swing code issu then why it is running on some PC's.
I have also tried to make connection in differenct thread but same problem.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10825

Can you be more specific on what you mean on "hang"
GUI is unresponsive (thats what I was thinking when I posted my previous reply)
Takes too much time to connect to the DB.
Anything else?
Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

If the PCs on which there is no problem can connect to the database very quickly then you will not notice anything. But if the other PCs cannot connect at all, it can take quite a while for the connection attempt to timeout, and the GUI will not respond for this entire duration.

How To Ask Questions How To Answer Questions
Kevin Parsons

Joined: Aug 09, 2011
Posts: 1

I'm having the same issue.

Using either NetBeans 6.9.1 or 7.0.1, Java 1.6 and Oracle 11g. I have the oracle JDBC jar files (ojdbc6_g.jar) within my project's library and when I run just the database connection code (no GUI interface), I'm able connect with no issues. As soon as I try to connect from within a GUI created by Netbeans (New Java Desktop Application Project), the thread blocks on...

If anyone has any suggestions or ideas I'd really appreciate it.
I agree. Here's the link:
subject: DriverManager.getConnection hangs from actionPerformed
It's not a secret anymore!