public static void handleAddCollection(RoutingContext routingContext){ Future<Void> futn=Future.future(); futn.setHandler(a->{ System.out.println("4最后一步:"); sendData(routingContext,"ok"); return; }); Future<UpdateResult> fut1 = Future.future(); JsonArray params=new JsonArray().add("123").add("测试标题").add("http://baidu.com").add(""); String sql="insert into mytable (userid,title,url,pic) values (?,?,?,?)"; myDBConnecton.updateWithParams(sql,params,fut1.completer()); fut1.compose(v-> { if(v.getUpdated()>0)System.out.println("2 插入成功了"); else System.out.println("2 插入失败了"); Future<ResultSet> fut2 = Future.future(); myDBConnecton.query("select * from mytable", fut2.completer()); return fut2; }).compose(v -> { List<JsonObject> data=v.getRows(); System.out.println("3查询结果为:"+data.toString()); Future<Void> fut3 = Future.future(); myDBConnecton.updateWithParams(sql,params,fut1.completer()); futn.complete(); },futn); }
执行结果显示:
2 插入成功了 3查询结果为:[{"id":1,"userid":120,"title":"测试标题","url":"http://baidu.com","pic":"","add_time":null}, {"id":2,"userid":120,"title":"测试标题","url":"http://baidu.com","pic":"","add_time":null}] 4最后一步:
本文出自 “北京看看” 博客,谢绝转载!
原文地址:http://kankan.blog.51cto.com/372369/1929999