Script Runner (Run DDL/SQL Scripts)

Runs DDL and SQL scripts. Typically these are scripts used for testing such as seed SQL scripts or truncate SQL scripts.

Scripts are executed in their own transaction and committed on successful completion.

Example of simple use

EbeanServer server = Ebean.getDefaultServer();

Example using place holders in the script

Map<String,String> placeholders = new HashMap();
placeholders.put("tableName", "e_basic");

EbeanServer server = Ebean.getDefaultServer();
server.script().run("/scripts/test-script.sql", placeholders);

In your SQL script, the way to reference the placeholder is:

delete from ${tableName}
select count(*) from ${tableName}

Notice that, the path to the script should start with "/". Ebean will do a this.getClass().getResource(PATH_TO_RESOURCE), so the resource should be available in your class path