I've created a python program that will convert CSV to JSON and insert the JSON data in the oracle database table. CSV to JSON is working fine, I'm able to connect oracle DB, but I'm getting an 'Error while inserting the data: expecting string or bytes object ' error while inserting the data. I'm using executemany function as it provides better performance than execute function. My parsed data is like this below:
[{'index': 0, 'Employee Name': 'Tom', 'Employee Age':35},
{'index': 1, 'Employee Name': 'Jackson', 'Employee Age':31}]
Below is my python code
df= pd.read_excel("demo.xls", sheet_name='a1')
result = df.to_json(orient='table')
parsed = json.loads(result)
try:
conn = oracle.connect("username","password","oracle_service_name")
except Exception as err:
print('Error while creating the connection: ', err)
else:
print('Oracle Version:', conn.version)
try:
cur = conn.cursor()
sql_insert = """INSERT INTO log(record,name,age) VALUES(:0,:1,:2)"""
cur.executemany(sql_insert, parsed['data'])
except Exception as err:
print('Error while inserting the data: ', err)
else:
print('Insert Completed.')
conn.commit()
finally:
cur.close()
conn.close()
Please help me to insert data in the table.
