• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem in getting the data from DB using servlets

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.






 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a lot of code. If you want good help I advise that you specify your question better.
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...


 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

for more understanding:
- ServletContextListener doc
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic