gpt4 book ai didi

java - 如何在 Java 中执行多条 sql 行?

转载 作者:行者123 更新时间:2023-11-29 11:50:24 25 4
gpt4 key购买 nike

这三行代码必须同时执行。

  SET @num := 0;

UPDATE your_table SET id = @num := (@num+1);

ALTER TABLE tableName AUTO_INCREMENT = 1;
********************************************************
Statement s1 = DataCon.getDataCon().createStatement();
s1.execute("SET @num := 0; UPDATE tblstaff SET staffid = @num := (@num+1); ALTER TABLE tblstaff AUTO_INCREMENT = 1");
s1.close();

最佳答案

试试这个!如果您想按数字顺序保存数据,我发现它非常有用

Statement stm = DataCon.getDataCon().createStatement(); 
String stm1 = "SET @num := 0";
String stm2 = "UPDATE tblstaff SET staffid = @num := (@num+1)";
String stm3 = "ALTER TABLE tblstaff AUTO_INCREMENT = 1";
stm.addBatch(stm1);
stm.addBatch(stm2);
stm.addBatch(stm3);
stm.executeBatch();
stm.close();

关于java - 如何在 Java 中执行多条 sql 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34190527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com