MySQL中如何同时执行多条语句? SELECT @max_id := MAX(id) FROM tab1;INSERT INTO tab1(id,name) VALUES(@max_id,'');我可以告诉你, 封装在事务中运行一定没有问题. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 START TRANSACTION;SELECT @max_id := MAX(id) FROM tab1;INSERT INTO tab1(id,name) VALUES(@max_id,'');COMMIT; try {connRemoteMysql.setAutoCommit(false);stmt = connRemoteMysql.createStatement();stmt.executeUpdate("SELECT @max_id := MAX(id) FROM tab1");stmt.executeUpdate("INSERT INTO tab1(id,name) VALUES(@max_id,'')");connRemoteMysql.commit();} catch (SQLException ex) { prt("SQLException: " + ex.getMessage()); try { if (connRemoteMysql != null){ prt("Rolling back transaction"); connRemoteMysql.rollback(); } } catch(SQLException rx) { prt("SQLException - rollback() failed: " + rx.getMessage()); } } finally { if (connRemoteMysql != null && !(connRemoteMysql.isClosed())) { connRemoteMysql.setAutoCommit(true); } } MYSQL存储过程删除重复数据,高手速度来 查询中case的问题 MYSQL 5.0.37 varchar长度必须为2的倍数吗? MYSQL4 有没有能存999,999,000这样格式的方法.而且要能计算的! 取一个表中 某个字段的重复数据? 我的MySQL 问题 在MySQL中如何执行*.sql脚本? 查询问题 mysql select查询语句 有两张表,从一张表对比另一张表找出缺少的记录,如何写这样的sql 刚在本地装上MySQL-Front,联接数据库时提示:Client does not support authentication ~~~ 求SQL语句,急!在线等!中午前结帖!
SELECT @max_id := MAX(id) FROM tab1;
INSERT INTO tab1(id,name) VALUES(@max_id,'');
COMMIT;
connRemoteMysql.setAutoCommit(false);
stmt = connRemoteMysql.createStatement();
stmt.executeUpdate("SELECT @max_id := MAX(id) FROM tab1");
stmt.executeUpdate("INSERT INTO tab1(id,name) VALUES(@max_id,'')");
connRemoteMysql.commit();
}
catch (SQLException ex) {
prt("SQLException: " + ex.getMessage());
try {
if (connRemoteMysql != null){
prt("Rolling back transaction");
connRemoteMysql.rollback();
}
}
catch(SQLException rx) {
prt("SQLException - rollback() failed: " + rx.getMessage());
}
}
finally {
if (connRemoteMysql != null && !(connRemoteMysql.isClosed())) { connRemoteMysql.setAutoCommit(true);
}
}