• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Data from database and showing through Servlets

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I have written a simple program to retirieve data from database using JDBC and show it in a web page through Servlets. It's a very simple and basic program which uses Class.forName, DriverManager.Connection, Connection.createStatement, Statement.executeQuery and then traversing the ResultSet. The first time when I run the servlet it correctly retrieves the data from the database and then displays it in the web page. I have placed the code in the doGet() method of the servlet. I have deployed the .war file in the webapps folder of the tomcat server.

Issue:

When I make some changes to the data in the databases and then re run the servlet then the servlet doesn't display the updated data it every time displays the data which it showed the first time. I have cleared the browser cache and I have revisited the code many times to see if something I am missing but I am not able to figure out the issue.

Please do help me. I am completely clueless as to what is happening.

Thanks and Regards,
Sid.

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sid,
First check that you've actually committed the changes to the database. (run "commit;"). This is the most frequent cause of stale data issues.

The second most frequent cause in caching. It doesn't sound like you've written any code to cache. But can you either set a breakpoint or add a println, to make sure it is running your statement/resultset code. Maybe the browser is caching?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic