I am developing one small application using servlets/JSP in tomcat server. Below is the sample coding I am using. I have used one class called connectionpool which will give us the connection. I am using that class to get the connection in servlet and then I am passing the connection to the helper class where all the database operations like insert,delete,update and select queries are done. I am passing the connection only and I am creating the statement and resultset in the helper itself and closing it there itself after getting & storing the required data from db. I am finally closing the connection in the servlet itself.
Sometimes the application is getting hanged and nothing is happening. I guess there is some connection pooling/performance problems are there,. I have the sample coding.
Is it right way of doing it? Any suggestion..how to use Apache Connection Pooling? any sample coding available on using.
Simplest form given. Sometimes, when I try to retrieve records the application gets hanged. no error message is displying in tomcat console... that'y I am asking if there is any flaw in my coding. for exmple I am trying to retieve the emloyee details from db. employee table has only limited records of 10-15 records only and sometimes even for this it's retieving and application gets hanged and if I deleting some records then it's working. Since It's not displaying any error message..I have doubts whether any flaw in the logic...
Mike, honestly I didn't get where the problem is, but i want you to try something which might be the reason. (i said might be).. your connection is being created over and over, which once I've read in an article that said it can't be, you should create it once, and close it once.. so it's better you try creating a Servlet implement of ServletContextListener, this servlet will run once your application is loaded, and it creates the connection, and assign it as a context scope attribute, check out the code:
This is the best way to have your connection "handy" by all servlets. try it, it might be the problem.
thanks for your reply. I will try this and post you the reply..thanks a lot.. I have seen in my code whenever I am clicking a link in the page it will go to the servlet and first it will create one connection...and i saw sometimes more than one connection is created..it will try it out & will post the reply
Joined: Nov 07, 2007
I have implemented your coding for getting the connection in the servlet context and it didn't and I have faced the same problem of keep on loading.. after a while, I have removed the "ORDER BY" in the query and to my surprise it's worjing properly and it's not keep on loading now. I think I haven't used the order by properly in sql query. Any body knows why using order by causing issues like this?
subject: Problem in getting the data from DB using servlets