我无法处理vertx-jdbc-client-3.3.9上JDBCClient中连接失败的情况,例如:没有要路由的主机,连接超时等,因为方法。getConnection()不返回failedFuture,即使在错误的主机名,用户名和密码上也不会调用failed。
只有当为连接提供的所有参数都有效时,该方法才会成功执行,否则代码块就会卡住,并且永远不会调用SQLConnection。 在我的情况下,即使用try catch块包装代码也不会出错。
JDBCClient client = JDBCClient.createNonShared(Holder.getInstance().getVertx(), databaseConfig);
client.getConnection(connect -> {
if (connect.failed()){
client.close();
return;
}
/* Create connection on success */
SQLConnection connection = connect.result();
/* Execute Query */
相关:未捕获Vertx连接超时JDBCClient(。GetConnection)
如果您使用C3P0连接池,请尝试以下操作:
databaseConfig.put("acquire_retry_attempts", 1).put("break_after_acquire_failure", true);
否则池将继续尝试建立连接。