(Oct-04-2016, 03:05 PM)nilamo Wrote:(Oct-04-2016, 12:14 PM)klllmmm Wrote:You close the cursor inside the for loop. The second time through the loop, the cursor isn't available anymore. That might not actually be your issue (the error looks like the Vehicle ID isn't available or something), but that is definitely AN issue.cur= conn.cursor() for i, row in enumerate(reader): # ... conn.commit() cur.close()
I know you can have multi-insert statements in sql server, mysql, and sqlite, but I don't know about oracle. That might be an easier way to do it (and also faster, since there'd only be a single insert/commit instead of one for each row). That would end up looking like this:
insert into Table_name (column1, column2, column3) values (value1, value2, value3), (another_value, another_value2, another_value3), (once_more, unto_the, breach)But all that said, the error you get doesn't really match what it looks like your code is doing, based off of your csv. Are there any rows in the file that don't have a vehicleno? You print each row in the for loop, at which point in the csv file, specifically, are you getting the error?
@nilamo Thank you very much, As u point out i should take out conn.commit & cur.close from the for loop.
Also for loop has to be change as :
if i >= 0: continuecontinue So now all the lines CSV file printed no error pops up, but it seems nothing is inserted into PostgreSQL data table, as nothing is printed when i run a select command.