This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes DB2 Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DB2 Connection" Watch "DB2 Connection" New topic

DB2 Connection

Matthew Lee

Joined: Apr 04, 2001
Posts: 1
When you put the statement.executeQuery(String) in the run() function for a thread does this use a different connection to the database or does it use the same Connection object?
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
It will use whatever Connection you used to create the Statement - unless you closed the connection, in which case it will throw an exception at you.
The Thread concerns me a bit, though. You are aware that JDBC connections aren't threadsafe? You would have to know exactly what you're doing, carefully establish responsibilities (which class & thread will close the connection and when, etc). It sounds like a refactoring candidate. But that's just a kneejerk reaction.
- Peter
I agree. Here's the link:
subject: DB2 Connection
It's not a secret anymore!