views:

49

answers:

3

I am developing a java web-site. It fetches data from http://projects.zoho.com.

I have to fetch data using its API and want to fill database in a session.

But, I need this process occur at deploy time. Means, at first time when I deploy web, it would fill whole database and then at every session period of time it fills data automatically.

What step I should follow ?

A: 

Write a ServletContextListener which populates the database and does the work in the contextInitialized() method.

If the listener is configured in your web.xml, the servlet container will invoke your listener's contextInitialized() method when the webapp is started.

matt b
A: 

you can see hibernate3:hbm2ddl maven plugin implementation for this purpose if your project is based on hibernate and for filling database in specific period of time you can define job in your application with quartz

AshkaN
A: 

This is a deployment issue, not a coding issue.
You should update your database with a script when you do your deployment.
You could automate this if you want in either ANT or Maven or whatever deployment script you are using.
Ideally the best time to do this is when your app is down, so you do not get any reads with the DB in an invalid state.

Romain Hippeau