initMySQLPool
package com.be.edge.asset.source; import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import io.vertx.mysqlclient.MySQLConnectOptions;
import io.vertx.mysqlclient.MySQLPool;
import io.vertx.sqlclient.PoolOptions;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import lombok.extern.slf4j.Slf4j; @Slf4j
public class MySQLVerticle extends AbstractVerticle {
private MySQLPool client; @Override
public void start(Promise<Void> startPromise) throws Exception {
initMySQLPool();
/*
client.query("SELECT * FROM data_list WHERE id = 1")
.execute(ar -> {
if (ar.succeeded()) {
RowSet<Row> result = ar.result();
log.info("Got {} rows {}", result.size(), result);
} else {
log.info("Failure {}", ar.cause().getMessage());
}
client.close();
});
*/ client.getConnection().compose(conn -> {
// All operations execute on the same connection
return conn
.query("SELECT * FROM data_list WHERE id = 1")
.execute()
.compose(res -> conn
.query("SELECT * FROM data_list WHERE id = 2")
.execute())
.onComplete(ar -> {
// Release the connection to the pool
conn.close();
});
}).onComplete(ar -> {
if (ar.succeeded()) {
RowSet<Row> result = ar.result();
log.info("Got {} rows {}", result.rowCount(), result);
for (Row row : result) {
log.info("data {} {}", row.getInteger(0), row.getString(1));
}
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
} private void initMySQLPool() {
JsonObject config = config();
MySQLConnectOptions connectOptions = new MySQLConnectOptions(config.getJsonObject("connect"));
PoolOptions poolOptions = new PoolOptions(config.getJsonObject("pool"));
client = MySQLPool.pool(vertx, connectOptions, poolOptions);
}
}
initMySQLPool的更多相关文章
- 基于 Serverless Component 全栈解决方案
什么是 Serverless Component Serverless Component 是 Serverless Framework 的,支持多个云资源编排和组织的场景化解决方案. Serverl ...
随机推荐
- C#的Skip 和 Take 方法
using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...
- 11 Self-Attention相比较 RNN和LSTM的优缺点
博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...
- druid连接池报错:sql injection violation, multi-statement not allow
druid连接池报错:sql injection violation, multi-statement not allow 需要配置druid的 multi-statement-allow属性为tru ...
- 在华为云上安装高可用 KubeSphere
随着多云多集群的场景越来越丰富,在各个云厂商环境部署 KubeSphere 的需求随之升高.由于各云厂商的云资源使用规则和菜单导航栏各不相同,会使用户花大量时间去排错.为降低部署过程错误率,本教程使用 ...
- 在 K8s 中快速部署使用 GitLab 并构建 DevOps 项目
作者:张海立,KubeSphere 社区 Ambassador.Talented Speaker,社区用户委员会上海站副站长 原文链接:https://kubesphere.com.cn/blogs/ ...
- 网页转换为PDF的方法 Python
前言 近期有些文档是在网站上的,量非常大.加之对于纸质书的喜爱,想把他们整合到一个PDF文档中,然后交由拼多多的老熟人打印店给打一下. 但是这个网站网页转PDF有很多在线网站可以用,不过只能转一个页面 ...
- mini-web 框架添加路由
阅读目录 1.mini web框架-4-路由 2.伪静态.静态和动态的区别 3.mini-web框架-实现伪静态url 4.准备股票数据 5.mini-web框架-从mysql中查询数据 6.mini ...
- 【JVM第3课】运行时数据区
运行时数据区结构图如下: 可分为 5 个区域,分别是方法区.堆区.虚拟机栈.本地方法栈.程序计数器.这里大概介绍一下各个模块的作用,会在后面的文章展开讲. 类加载子系统会把类信息加载到方法区,程序运行 ...
- Android添加OpenCV支持
首先下载OpenCV的SDK 推荐在官网下载. 官网地址:https://opencv.org/releases/ 也可以在OpenCV的GitHub上现在 GitHUb链接:https://gith ...
- win10启用长路径
方法一:操作组策略 Win+R 输入 gpedit.msc 依次点击[计算机配置]->[管理模板]->[系统]->[文件系统],找到 "启用win32长路径" 并 ...