Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can statement be used in multi-thread?

 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
I am new to JDBC,
I wonder if the statement can be used in multi-thread. I mean i create a statement object by Connection. And pass the reference to mutli-thread, then mutli-thread uses the statement to executeQuery, can it work? And can preparedStatement work that way?

i write some code to test

It seems to work fine, every thread get the correct result.
But is there any guarantee?

I know Connection can be used concurrently by many users, but how many is appropriate?

Thank you in advance,
William.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SCJP is the wrong place to post this question. Moving to somewhere where topic is likely to be answered. Let's try JDBC.

- dumplicated here!
[ November 28, 2006: Message edited by: Barry Gaunt ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my view.. you should NOT use same statement in muti threaded environment. A statement is tightly coupled with Connection, and any commit/rollback will affect operation of every thread...

Shailesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic