Executing SQL statements at deployment time
Skip to end of metadata
Go to start of metadata

How to execute SQL statements during deployment

The article is about how to execute some cleanup or initialization SQL statements during the deployment time of, for example, a data source. Below is an example of how this can be done.

The following are the dependencies used in this example:

  • my-sql.jar containing the .sql files to be executed (this has nothing to do with MySQL, it's just a jar file containing .sql files, nothing more).

How it works

We must specify a GBean in the connector deployment descriptor. This gbean will execute during deployment time. But it needs the following information:

  1. Name of a Datasource to execute on
  2. Path to the .sql file
  3. A test sql query that will act as a boolean. If the query returns zero number of records, the sql statements will be executed (e.g. you may want to create some tables)
Labels
  • No labels