Poma
Poma

Reputation: 8474

How to execute sql file in play framework 2.0?

I have an .sql file that needs to be run every day on scheduler. I found that schedulers are done via Akka. Now how to execute an sql file in play framework 2? Ebean only allows me to execute single query.

Upvotes: 3

Views: 1894

Answers (1)

ndeverge
ndeverge

Reputation: 21564

I think you can use a raw JDBC connection, and use the ScriptRunner class provided here: https://gist.github.com/831762/

Play provides a helper to get a JDBC connection:

java.sql.Connection connection = play.db.DB.getConnection();

and then:

ScriptRunner runner = new ScriptRunner(con, autoCommit, stopOnerror);
runner.setDelimiter(";", true);
runner.runScript(new BufferedReader(new FileReader("yourFile.sql")));

Upvotes: 4

Related Questions