Created
May 7, 2017 13:44
-
-
Save cescoffier/96cb0b5c4fcceda6c3f32147d6934cb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
matching the instance of error with SQLNonTransientException would be better.