Most exalted ones,
Is it better/preferred to instantiate one Connection object and then pass
this object to different parts of the client application that need to
execute queries, then close the connection when the application terminates?
Or should one instantiate a new connection object in each method that
executes a query or whatever, then close it when finished?
Related, Is it necessary to explicitly call close() on a connection?
My reason for asking is that my application monitors incoming and outgoing
network traffic and writes it to either an incoming or outgoing table within
the database. I'm using the data access object pattern and have a DAO class
to handle db inserts into each of the tables. The nature of the network
traffic I'm monitoring causes rapid fire inserts into the db on the order of
dozens of times per second. Right now I have it set up that each of my DAO
class has an insert() method that creates a connection, creates an insert
query based on that connection, then closes the connection.
It appears that I might be overloading the abilities of something, because
my app crashes when the network traffic goes really high and causes a huge
number of calls to my DAO insert() method.
The only thing I can think of is that maybe the app can't create/close
connections or queries fast enough. I have all of my db code in try/catch
blocks and have not gotten any errors.
Any thoughts you have on how to handle this sort of thing properly are
This e-mail and any attachments are provided through AEgis
Technologies' e-mail services and may contain company sensitive and/or
privileged information. If you are not the intended recipient, please
notify the sender immediately by return e-mail, delete this e-mail and
destroy any copies. Any dissemination or use of this information by a
person other than the intended recipient is unauthorized and may be