This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes DB2 Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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
subject: DB2 Connection
Similar Threads
closing the database connection
Dirty read (?) problem
JavaBean in Servlet?
PreparedStatement with Connection Pooling