0

0

分享

python执行批量新增sql报错? not enough arguments for format string?

49 0
发表于 2024-7-7 10:17:18 | 显示全部楼层 阅读模式
悬赏1金钱未解决
  1. import pyodbc
  2. from sqlConfig  import MySQLConnectionPool

  3. # 连接数据库
  4. conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\东和.accdb')

  5. # 创建连接池对象
  6. ConnPool = MySQLConnectionPool()

  7. # 创建游标
  8. cursor = conn.cursor()

  9. # 查询数据
  10. cursor.execute('SELECT * FROM 配方列表')

  11. list1 = []
  12. # 逐行读取数据
  13. for row in cursor.fetchall():
  14.     list1.append(row)
  15. print(list1)
  16. #list = cursor.fetchall()
  17. sql_update_one = "delete from plan_peifang_list where 1=%s"
  18. ConnPool.update_one(sql_update_one, (1,))

  19. a= [('D033', '吉林建龙', 'AMC72/10Z5-8A2', None, '2024/5/31 9:00:24', None), ('D074', '鞍钢联众', 'MAC65/18F5-10Pa24', None, '2024/4/30 9:12:50', None), ('D033', '吉林建龙', 'AMC72/10Z5-8A2', None, '2024/5/31 9:00:24', None), ('D033', '吉林建龙', 'AM88/6W-L10', None, '2024/5/29 15:31:16', None), ('E005', '塔塔布衫', 'MC14H2Pa24-42C3D3', None, '2024/6/1 15:34:59', None), ('D033', '吉林建龙', 'MC12H4P2-4S9', None, '2024/6/3 6:12:35', None), ('E005', '塔塔布衫', 'MC12H3Pa24-41C3G1', None, '2024/6/3 8:15:18', None), ('E035', '米塔尔', 'MC13H2PA24-4C2', None, '2024/6/3 15:19:34', None), ('E024', '香港泰科', 'MC10H3P2-3D3', None, '2024/6/4 6:53:56', None), ('E039', '瑞钢国际', 'MC14H2PA24-8C2', None, '2024/6/4 14:32:25', None), ('E038', '瑞钢国际', 'MC12H3P2-8C2', None, '2024/6/4 16:00:51', None), ('D033', '吉林建龙', 'AM82/8Z5-L10', None, '2024/6/6 16:33:46', None), ('D023', '北方冶金', 'MC16H2A5', None, '2024/6/6 16:48:42', None), ('D023', '北方冶金', 'MC15F5P2-43H5C6', None, '2024/6/7 14:26:36', None), ('D033', '吉林建龙', 'MAC60/20Y5-10', None, '2024/6/13 17:56:39', 'TRL HMR LSKS'), ('D059', '吉林建龙', 'MAC55/25Y5-8', None, '2024/6/13 10:38:08', 'SWC30H'), ('E038', '瑞钢国际', 'MC12H2P2-8C2', None, '2024/6/8 19:10:57', None), ('E037', '德富高', 'ASC62/10X4-12', None, '2024/6/11 8:09:23', 'DF12X10'), ('D038', '德龙钢铁', 'MC10C1RBA235', None, '2024/6/11 15:17:45', '出钢口'), ('E037', 'DUFERCO', 'ASC73/8B-10A2', None, '2024/6/12 11:07:08', 'DF10K8'), ('E041', '香港泰科', 'MC10H2Pa22-5D3', None, '2024/6/12 20:06:05', 'SWC30H'), ('E000', 'LADLE', 'MC14H3Pa24-4C3', None, '2024/6/13 15:00:17', 'TRL HMR LSKS'), ('E042', '东和欧洲', 'MC12H2PA24', None, '2024/6/13 19:06:19', 'CMAG12H2A4'), ('E042', '东和欧洲', 'MC10C2P2', None, '2024/6/13 22:03:29', 'CMAG 10C2A01')]
  20. print(a)
  21. #sql_insert_all = "insert into plan_peifang_list ('dingdanhao', 'kehu', 'zhilianghao','zhongliang','time','waibuzhilianghao') values (%s,%s,%s,%s,%s,%s)"
  22. sql = "INSERT INTO plan_peifang_list (dingdanhao, kehu, zhilianghao, zhongliang, time, waibuzhilianghao) VALUES (%s, %s, %s, %s, %s, %s)"
  23. ConnPool.insert_all(sql, list1)
复制代码


回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系企业客服

Cpoyright © 2021-2025 Discuz! X 版权所有 All Rights Reserved.

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0

关灯 在本版发帖
联系企业客服
返回顶部
快速回复 返回顶部 返回列表