Я пытаюсь записать pandas dataframe в базу данных Teradata, используя Jaydebeapi. Я могу легко читать данные из базы данных, но столкнулся с проблемой при записи.
Код:
import jaydebeapi
import pandas as pd
case_detail_server ='server_url'
server_name= 'servername'
user ='xyz'
password ='****'
jars= ['/anaconda3/lib/tdgssconfig.jar','/anaconda3/lib/terajdbc4.jar']
#jars= ['/anaconda3/lib/terajdbc4.jar']
jclassname_case_detail='com.teradata.jdbc.TeraDriver'
teradata_url='jdbc:teradata://server_url/DBS_PORT=1025,TMODE=ANSI,CHARSET=UTF8'
conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',teradata_url,{'user': user, 'password': password},jars)
curs = conn.cursor()
Способ 1:
Pandastable быть написанным => df_out
for row in df_out.head().iterrows():
curs.execute("INSERT INTO TD_table(column1, column2) VALUES(?,?)", row)
Ошибка 1
Error
---------------------------------------------------------------------------
Error
Traceback (most recent call last)
<ipython-input-390-8067f51cb5e3> in <module>
1 for row in df_out.head().iterrows():
----> 2 curs.execute("INSERT INTO CTD_table(column1, column2) VALUES(?,?)", row)
/anaconda3/lib/python3.6/site-packages/jaydebeapi/__init__.py in execute(self, operation, parameters)
492 def execute(self, operation, parameters=None):
493 if self._connection._closed:
--> 494 raise Error()
495 if not parameters:
496 parameters = ()
Error:
Метод 2:
resultset=[]
for column1,column2 in df_out:
try:
resultset.append((column1,column2))
except AttributeError:
pass
curs.executemany("INSERT INTO CTD_table(column1, column2) VALUES (?,?)",resultset)
Ошибка 2
ValueError: too many values to unpack (expected 2)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-392-71473191f932> in <module>
1 resultset=[]
----> 2 for column1,column2 in df_out:
3 try:
4 resultset.append((column1,column2))
5 except AttributeError:
ValueError: too many values to unpack (expected 2)```