I have a war file with my webapp and I need to generate the database tables in MySQL in the moment when I have copied the war to the webapps folder from Tomcat (assuming Tomcat is running).
Is there a way to do this, can you help me with some information about this?
PS. It’s a very simple webapp, using just JDBC, i don’t use any ORM frameworks. Is it possible with JDBC?
Do the job in the
contextInitialized()method of a customServletContextListenerclass. This will be invoked when the webapp starts up.That said, using an ORM framework like JPA/Hibernate really saves you from a lot of JDBC boilerplate code and headaches.