0

I have been trying to load the SQL script schema into MySQL DB using Vertx.
Though, i am able to load or update any single DB command but unable to load complete schema in one go.

The second challenge faced is that, this might be blocking code for Vertx application. If that is the case, how can it be avoided?

Here is the code snippet i have been trying to execute:

  jdbcClient.getConnection(resConn -> {

                    if(resConn.succeeded()) {

                        SQLConnection connection = resConn.result();

                        connection.execute("<Trying to load the SQL Script schema>", resSchema -> {


                            connection.close();
                            if(resSchema.succeeded()) {

                                async.complete();
                            } else {
                                testContext.fail("Failed to load bootstrap schema: " + resSchema.cause().getMessage());
                            }
                        });
                    } else {
                        testContext.fail("Failed to obtain DB connection for schema write");
                    }
                });
epiyugu
  • 13
  • 5

1 Answers1

1

The MySQL JDBC driver does not allow to execute a file as a SQL script. You must parse the script and execute individual commands one by one.

tsegismont
  • 8,591
  • 1
  • 17
  • 27
  • Thank you for the response. Working with Vertx, if i manage to load the SQL script, will that not block the thread and might halt the application? – epiyugu Dec 15 '17 at 09:35
  • If the script is very long you can wrap the processing of it in executeBlocking. – Xargos Dec 15 '17 at 10:06