This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There is a combobox in a jsp for which the values will be populated from a database table. This combo box displays different countries available. We know that the country listing dont change very often, but still we are not sure whether any country can be added or deleted. We dont want to get the data every time from database. But whenever a new country is added or existing country is deleted, immediately the change should be reflected in the jsp page. we know that we can use a jsp:include and do this. but it will be fetching data everytime from db which I dont like. If we use a include directive, then insert or delete from the table will not be reflected in the jsp unless a change is done in parent page. which is the best way to achieve the above requirement?
Joined: Mar 07, 2005
one additional information The combo box will be there in almost all the jsp pages in the website. thats why we plan to make it a included page.
Cache the data in a collection, and display from there. Maintain a local file that stores the last DB read date. (app_db_read)
Write a INSERT/ UPDATE/ DELETE trigger that updates the update time in a one column table (country_update), or, updates a file (db_update) on the disk with the new timestamp, when a new country is added/ deleted. I am not sure of triggers can write to system files - read on.
The code that fetches data from the collection compares the date in the local file app_db_read, and the country_update, or, the file that the trigger updated - db_update (if possible), just before reading the collection. If the date is same, data has not changed, continue reading the cached data. If the dates are different, data has changed, update the collection, and read the new data from the collection.
If triggers can write to system files, your problem is solved without a DB call. If not, yes, there is still a DB read call from the country_update table, but thats really a one value update_date fetch unlike a collection of values fetch. And I dont see any other way how a data change at the DB level would be alerted in the application.
[ October 06, 2005: Message edited by: J Singh ] [ October 06, 2005: Message edited by: J Singh ]