Q:

How to do Database Execution while deploying War

I don't know but Is this possible to do the following?
I have a situation, where I have to retrieve data from Ldap and put those in MySQL database using Hibernate.
This would be a one time execution. I don't need to get the data from Ldap periodically.
In this situation, is that possible to do the above mentioned procedure at the time of the deployment of the Application?
If possible? Can I have a simple Example of the solution?
Please Help.
Alternative Solution to the problem is also welcome.
Thanks in advance.

A:

Hoping you are using a servlet container.
Use a ServletContextListener interface and plug this into the web.xml as a listener.
 public class MyClass implements ServletContextListener {
    .... Query LDAP
    .... Insert into DB
 }

Note that no exceptions must be thrown to MyClass because ContextListener architecture is not expecting it to happen, and application wont startup.

