Error handling - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Error handling (/thread-10917.html) |
Error handling - parthi1705 - Jun-13-2018 Error handling Hi, How to handle errors and exception in Python. I have mixed columns in mytable with Integer and varchar in my sql database. I am having a csv file with million of records in it it consists of 20 columns. Column3 is a string or varchar() in DB. in DB Column3 has varchar(100). suppose in the csv file in the column3 if the lenght is more than 100 char it is not inserted, rest of the rows also failing, no records has been inserted. this kind of issues can be fixed with other tools, but how can we fix in Python. how to seperate the lenght issue column while inserting into DB. If below is my code import pyodbc cnxn = pyodbc.connect(r'DSN=myDSN;UID=userid;PWD=password') crsr = cnxn.cursor() crsr.execute("""BULK INSERT mytable FROM 'D:\my.csv' WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )""") cnxn.commit() crsr.close() cnxn.close()How to handle errors and exception in Python in those cases. Also how to commit for every 10K Thanks in advance. |