无法将值字符串传递到适用于Python的mySQL连接器中

问题描述

我正在尝试完成HW作业,其中我必须使用MysqL连接器使用Python将字典中的值传递到MysqL表中。为此,我将字典值转换为可以传递给INSERT查询的字符串。

这是我传递给命令的'values字符串(只需替换值以查看代码是否有效):

1,1,1,1,1,111-111-1111,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ,1、1、1、1、1、1、1、1、1、1、1、1、1、1、1、1、1、1、1,1

由于某种原因,每次我尝试运行此代码时,都会出现以下错误

MysqL.connector.errors.DatMysqL.connector.errors.ProgrammingError:1064(42000):您的sql语法有一个错误。查看与您的MysqL服务器版本相对应的手册以获取正确的语法以在'1、1、1、1、1、1、111-111-1111、1、1、1、1、1、1、1、1、1、1附近使用第1行的11,1,1,1,1,1,1,1,1,1,'

aError:1136(21S01):列数与第1行的值数不匹配

import MysqL.connector
db = MysqL.connector.connect(user ='root',host = 'localhost',password ='fiddlere2012!',db='py')
cursor = db.cursor() 
values = ','.join((tuple(mds.values())))
print(values)    
insertmds = ('INSERT INTO mds' 
            '(manufacturer,location,contact,address,email,phone,modelNumber,moduletotalLenxWid,moduleWeight,indCellArea,cellTech,cellManufacturer,cellManuLocation,totalCells,cellSeries,seriesstrings,bypassdiodes,bypassdioderating,bypassdiodeMaxTemp,seriesFuserating,interconnectMatSupModNo,interconnectDims,superstrateType,superstrateMan,substrateType,substrateMan,frameType,frameAdhesive,encapsulantType,encapsulantMan,juncBoxType,juncBoxMan,juncBoxPottingMat,juncBoxAdhesive,juncBoxUse,cableConnectorType,maxSysVoltage,voc,isc,vmp,imp,pmp,ff)' 
            'VALUES ((%s))' % (values))

cursor.execute(insertmds)

如果可以的话,请帮助我找出我在做什么错..谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)