top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

I am opening a single JDBC connection in my init() method. ......or the Statement object?

+1 vote

I am opening a single JDBC connection in my init() method. Do I need to synchronize on the Connection or the Statement object?

posted Oct 27, 2015 by Dominic

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You shouldn’t have to. If your JDBC driver supports multiple connections, then the various createStatement methods will give you a thread-safe, reentrant, independent Statement that should work OK, even if other requests/threads are also accessing other Statements on the same Connection. Of course, crossing your fingers never hurts… Many early JDBC drivers were not re-entrant. The modern versions of JDBC drivers should work OK, but there are never any guarantees.
Using connection pooling will avoid the whole issue, plus will lead to improved performance.

answer Oct 29, 2015 by Karthick.c
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.