老师我不开启事务机制,执行了数据库没有生效,只有把事务机制开启了数据库才有生效
import mysql.connector.pooling
config = {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "123456",
"database": "demo"
}
try:
pool = mysql.connector.pooling.MySQLConnectionPool(
**config,
pool_size=10
)
con = pool.get_connection()
# con.start_transaction()
cursor = con.cursor()
sql = "INSERT INTO t_dept(deptno,dname,loc) VALUES(%s,%s,%s)"
data = [
[100, "A部门", "北京"], [110, "B部门", "上海"]
]
cursor.executemany(sql, data)
# con.commit()
except Exception as e:
# if "con" in dir():
# con.rollback()
print(e)
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星