Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error handling
Error handling

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
How to handle errors and exception in Python in those cases.
Also how to commit for every 10K

Thanks in advance.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error Handling JarredAwesome 5 250 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome
  Error handling using cmd module leifeng 3 442 Jun-06-2020, 06:25 PM
Last Post: leifeng
  Excpetion Handling Getting Error Number gw1500se 4 404 May-29-2020, 03:07 PM
Last Post: gw1500se
  Warning / Error handling in python Prarthana_12 1 2,035 Feb-08-2019, 09:21 PM
Last Post: snippsat
  Help With Error Handling jo15765 6 1,411 Sep-14-2018, 06:27 PM
Last Post: jo15765
  Error Handling/No results from SQL Query JP_ROMANO 7 3,083 Jul-18-2018, 02:31 PM
Last Post: JP_ROMANO
  Error Handling is weird PythonAndArduino 1 1,367 Nov-09-2017, 05:08 AM
Last Post: Mekire
  Error handling not working desudesu 2 1,851 Jun-14-2017, 02:12 PM
Last Post: desudesu

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020