Skip to content

Instantly share code, notes, and snippets.

@cescoffier
Created May 7, 2017 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cescoffier/96cb0b5c4fcceda6c3f32147d6934cb2 to your computer and use it in GitHub Desktop.
Save cescoffier/96cb0b5c4fcceda6c3f32147d6934cb2 to your computer and use it in GitHub Desktop.
@Override
public void start(Future<Void> fut) {
jdbcClient = JDBCClient.createShared(vertx, new JsonObject()
.put("url", "jdbc:mysql://localhost:3306/data")
.put("driver_class", "com.mysql.cj.jdbc.Driver")
.put("user", "user")
.put("password", "secret")
.put("max_pool_size", 30));
Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
jdbcClient.rxGetConnection()
.flatMap(connection -> connection
.rxExecute("create table crime(id int primary key, name varchar, villain varchar, wiki varchar)")
.flatMap(v ->
connection.rxExecute("insert into crime values(1, 'Moon', 'Gru', 'https://en.wikipedia" +
".org/wiki/Moon'), "
+ "(2, 'Times Square JumboTron', 'Gru', 'https://en.wikipedia.org/wiki/One_Times_Square'), "
+ "(3, 'Kryptonite', 'Lex Luthor', 'https://en.wikipedia.org/wiki/Kryptonite')"
)
)
.doAfterTerminate(connection::close))
.subscribe(
server -> {
System.out.println("Done !");
fut.complete();
},
error -> {
System.out.println("Error while connecting to the database");
if (error instanceof SQLSyntaxErrorException) {
System.out.println("Error code: " + ((SQLSyntaxErrorException) error).getErrorCode());
}
fut.fail(error);
});
}
@akshaykumar3
Copy link

matching the instance of error with SQLNonTransientException would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment