Is it a good idea to declare your connection object globally, open the connection in init and close it on destroy? Or is it better to just open and close it all in a doGet or doPost each time a thread request the servlet?
Created May 7, 2012
Alex Chaffee Globally. Definitely. It can take upwards of 10 seconds or even several minutes to open a DB connection (depending on your sever and drivers).
See How do I access a database from my servlet or JSP?... and the topic Servlets:Databases