In my application i have around 7 or 8 servlets and some jsps.
for database connections i have my own class say, DBConnector, which when instantiated will connect to the specified database.
at present i am instantiating this class DBConnectgor in every servlet for making a database connection. but i feel that this may overload and consume the server's time if the application becomes large. So i want this class to get instantiated when the server starts, so that the connection is made with the database and further i must be able to use this single connection all through the application for all the clients requests.
please help me in this regard. which is the best practice of maintaining database connection? should i register my database in the server's JNDI? i am using tomcat 5.0 server
Yeah it will be better if you instantiate it in the context listener. Another better solution is you need not have to instantiate the class. You can have static method which serves you the connection Object. Further you can go for singleton pattern if you want to have only one connection
We're pleased to have you here with us in the servlets forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.