Hi There,
Just had a quick question. Assume that we made a singleton class which
would return the reference to an already existing Connection (made
using DriverManager.. no connection pooling).
I would assume, that calling createStatements in a server/client
application would fail because a connection encapsulates the database
server and client information (IP ADDRESSES). So multiple clients with
different ip addresses would not be able to use someone's else
connection object... is this right?
Now, what if in a multi-threaded environment there is only one client
and one server... There is stil only one connection object (created by
the client). Calling createStatement should work everytime, right? Now
what about cuncurrency issues... if two statements are created then
they execute excuteUpdate() at the same time, will the connection
object simultaneously execute the queries, or will it queue them up?
Thanks..
Fredrik Bertilsson - 20 Aug 2004 16:40 GMT
A java.sql.Connection object is only valid and useful on one machine
(client or server). It is not Serializable. Each client need to have
their own connection object. But if the connection object are pooled
on the server side, the pool have to be thread-safe. It can be very
confusing results, if two threads are using the same connection object
concurrent.
/Fredrik