Atomicity , uniformity , Isolation , persistence
Start transaction manually :db.Begin()-->Tx
a set sql operation
tx.Exec(),tx.Prepare()...

Submit manually , RollBACK

tx.Commit(),tx.Rollback()

package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql"
)func main() { /* affair : 4 Big features :ACID Atomicity : uniformity : Isolation : Permanence : */
//rose-->jack,2000 element db, _ := sql.Open("mysql",
"root:hanru1314@tcp(127.0.0.1:3306)/my1802?charset=utf8") // Open transaction tx, _ :=
db.Begin()// Provide a group sql operation var aff1, aff2 int64 = 0, 0 result1, _ := tx.Exec("UPDATE
account SET money=3000 WHERE id=?", 1) result2, _ := tx.Exec("UPDATE account
SET money2=2000 WHERE id=?", 2) //fmt.Println(result2) if result1 != nil { aff1,
_ = result1.RowsAffected() }if result2 != nil { aff2, _ = result2.RowsAffected()
; } fmt.Println(aff1) fmt.Println(aff2) if aff1 == 1 && aff2 == 1 { // Commit transaction
tx.Commit() fmt.Println(" The operation was successful ..") } else { // RollBACK tx.Rollback() fmt.Println(
" operation failed ... RollBACK ..") } }

Technology
©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network