4

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.

1

1 Answer 1

8

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

... this doesn't actually work. It interprets the SQL and sometimes it breaks. For example on Oracle it gives error if your SQL contains stuff like trigger definitions with multiple statements...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.