vert.x-使用jdbc驱动程序在批量插入中保留行顺序

wfsdck30  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(188)

我正在尝试使用vertxjava在mssql数据库中进行大容量插入,由于某些原因,在表中插入的顺序与在列表中排列数据的顺序不同。对于我的业务逻辑来说,在数据库中有这个顺序是非常重要的。在控制台中,它正确地显示了顺序,但是当我在数据库中查看它时,顺序是完全混淆的。

public void insertChildUid(SortedSet<String> goodReadSet, Integer serialID) {
        LOG.debug(" serialID "+serialID);
        List<JsonArray> batch = new ArrayList<JsonArray>();

        int childSetSize = goodReadSet.size();
        LOG.debug(" childSetSize "+childSetSize);
        String[] goodReadArray = new String[childSetSize];
        goodReadArray = goodReadSet.toArray(goodReadArray);

        for (int i=0; i < childSetSize; i++) {
            String[] puidAndUid = new String[1];            
            puidAndUid = goodReadArray[i].split(":");
            String puid = puidAndUid[0];
            String uid = puidAndUid[1];

            batch.add(new JsonArray().add(uid).add(puid).add(serialID));
        }
        String sql = "INSERT INTO serial"
                        + " (uid, fnc, serialorderid)"
                        + " VALUES(?, ?, ?) ";

        LOG.debug("SQL QUERY :"+formatQuery(sql, batch));

        dbClient.getConnection(conn->{
            if(conn.failed()){
                LOG.error("Can't get Vertx connection",conn.cause());
            } else{
                LOG.debug(" Vertx connected for BATCH INSERT!!!!!!!!!");

                final SQLConnection connection = conn.result();                          
                connection.batchWithParams(sql,batch,(AsyncResult<List<Integer>> res) -> {
                  if (res.succeeded()) {
                        List<Integer> result = res.result();
                        LOG.debug("result : "+result.size());
                        //LOG.debug("BATCH INSERT COMPLETE!!!!!!!!!");
                        LOG.debug(" BATCH INSERT COMPLETE FOR PUID!!!!!!!!! "+batch.get(0).getString(1));
                      } else {
                        // Failed!
                          LOG.debug("Failed! : "+res.cause());
                      }
                    });
                connection.close();
            }
        });

    }

下面是我的控制台输出

11:41:04.569[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-childsetsize 10
11:41:04.570[vert.x-eventloop-thread-1]debug tntmanual.server.dao.serialorderdao-sql查询:插入串行(uid,fnc,serialorderid)值([[“1198000533980079304”,“11980180231000164186”,72],[“11980013237900080767”,“11980180231000164186”,72],[“11980018018100688258”,“11980180231000164186”,72],[“11980018208300933667”,"11980180231000164186",72], ["11980018213800239089","11980180231000164186",72], ["11980018531200237597","11980180231000164186",72], ["11980023406000938288","11980180231000164186",72], ["11980027390300806466","11980180231000164186",72], ["11980028239900198090","11980180231000164186",72], ["11980028320100716616","11980180231000164186",72]], {1}, {2})
$$$$$$$$ 11980183084300807471 $$$$$$$$$$$
11:41:04.571[vert.x-eventloop-thread-1]调试tntmanual.server.dao.orderdao-arraysize 5
11:41:04.572[vert.x-eventloop-thread-1]调试tntmanual.server.dao.orderdao-arraysize+childcounter 1510迭代集合:5 constr serialorderdao!!
11:41:04.572[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-serialid 72
11:41:04.572[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-childsetsize 5
11:41:04.572[vert.x-eventloop-thread-1]debug tntmanual.server.dao.serialorderdao-sql查询:插入序列(uid,fnc,serialorderid)值([[“11980053655800913678”,“11980183084300807471”,72],“1198008027370614629”,“11980183084300807471”,72],“1198008202860001574”,“11980183084300807471”,72],“1198008222200979”,"11980183084300807471",72], ["11980088238100084516","11980183084300807471",72]], {1}, {2})
11:41:04.572[vert.x-eventloop-thread-1]debug tntmanual.server.dao.orderdao-创建序列并保存在数据库中
11:41:04.573[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-vertx已连接以进行批量插入!!!!!!!!!
11:41:04.576[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-vertx已连接以进行批量插入!!!!!!!!!
11:41:04.585[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-结果:5
11:41:04.585[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-完成puid的批插入!!!!!!!!!11980183084300807471
11:41:04.585[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-结果:10
11:41:04.585[vert.x-eventloop-thread-1]调试tntmanual.server.dao.serialorderdao-完成puid的批插入!!!!!!!!!11980180231000164186*
[![数据库中的表输出][1]][1][1]:https://i.stack.imgur.com/yj49u.gif

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题