getting error while importing excel data into mysql using python only one row inserted -
sir
i trying import excel data mysql using python of video tutorial have following issue:
only first row in excel file inserted mysql , getting following error
cursor.execute(query, values) line 179 in execute
here code
import xlrd import mysqldb book=xlrd.open_workbook("c:\python27\mygdata.xls") sheet=book.sheet_by_name("sheet1") database=mysqldb.connect(host="localhost", user="root", passwd="sharan246", db="test1") cursor=database.cursor() query=""" insert omrdata (regno,name,subject,barcode,flag1) values (%s,%s,%s,%s,%s)""" r in range(1, sheet.nrows): regno = sheet.cell(r, 0).value name= sheet.cell(r, 1).value subject=sheet.cell(r, 2).value barcode=sheet.cell(r, 3).value flag1=sheet.cell(r, 4).value values=(regno,name,subject,barcode,flag1) cursor.execute(query, values) cursor.close() database.commit() database.close() print "" print "all done bye now" print "" columns=str(sheet.ncols) print"i imported"
please me
you close cursor cursor.close()
database.close()
inside loop open once @ beginning. try moving lines outside of loop , see if it's going help.
Comments
Post a Comment