vaibhav.g
vaibhav.g

Reputation: 759

How to run sql script file using JDBI

I am using jdbi to make connection to db and execute sql command.

dbi = new DBI("jdbc:mysql://"+dbHostName+"/"+dbName, "root", "");
    dbi.withHandle(new HandleCallback<Object>() {
        @Override
        public Object withHandle(Handle handle) throws Exception {
            handle.execute("Query to execute")
            return null;
        }
    });

Now i want to run sql file using jdbi. I googled a lot but couldn't figure out how.

Upvotes: 4

Views: 3614

Answers (1)

Deinlandel
Deinlandel

Reputation: 1033

You should read your sql file to string and then execute it like

String script = ".. your sql file contents here ..";
try (Handle h = dbi.open()) {
    h.createScript(script).execute();
}

Upvotes: 8

Related Questions