Connection conn = ConnectionManager.getConnection();
try {
conn.setAutoCommit(false);
String brand_id=null;
sql = "INSERT INTO `ig_brand`(name,icon,description,brand_label) VALUES(?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sb2.toString(), Statement.RETURN_GENERATED_KEYS);
pstmt.setString(1, brand);
pstmt.setString(2, brand_logo);
pstmt.setString(3, madein);
pstmt.executeUpdate();
//检索由于执行此 Statement 对象而创建的所有自动生成的键
ResultSet rs = pstmt.getGeneratedKeys();
if (rs.next()) {
//知其仅有一列,故获取第一列
brand_id = rs.getLong(1)+"";
}
sql = "UPDATE quick_order a SET a.`status` = 2, a.send_time = now() WHERE a.brand_id=? and merchant_id=?";
int count = DbTools.executeUpdate(sql, DbTools.makeParams(express_number, brand_id, merchant_id));
}
} catch (Exception e) {
e.printStackTrace();
try {
conn.rollback();
} catch (SQLException e1) {
e.printStackTrace();
}
} finally {
try {
conn.setAutoCommit(true);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException();
}
ConnectionManager.returnConnection(conn);
}
sql插入并返回自增主键
最新推荐文章于 2023-02-02 17:07:10 发布