Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to executemany #216

Open
ccqz opened this issue May 13, 2022 · 1 comment
Open

how to executemany #216

ccqz opened this issue May 13, 2022 · 1 comment

Comments

@ccqz
Copy link

ccqz commented May 13, 2022

I wish query oracle test.A table to insert oracle MAEAS.A table , it use executemany and batch run.

`
import sys
import os
import jaydebeapi

url = 'jdbc:oracle:thin:@8.142.180.78:1521:MAEASDB'
driver = 'oracle.jdbc.driver.OracleDriver'
userFrom = 'test'
passwordFrom = 'test'
jarFile = 'D:/Tools/JDBC/ojdbc8.jar'
connFrom = jaydebeapi.connect(jclassname=driver,
url=url,
driver_args=[userFrom, passwordFrom],
jars=jarFile)
cursFrom = connFrom.cursor()
userTo = 'MAEAS'
passwordTo = 'MAEAS'
jarFile = 'D:/Tools/JDBC/ojdbc8.jar'
connTo = jaydebeapi.connect(jclassname=driver,
url=url,
driver_args=[userTo, passwordTo],
jars=jarFile)
cursTo = connTo.cursor()
sqlStr = 'select FREGIONCODE, FCATEGORYNUMBER, FCATEGORYNAME, FCATEGORYSUBCODE, FCATEGORYSUBNAME, FPAYITEMNUMBER, FPAYITEMNAME, FPAYITETYPE, FCATEGORYID, FCATEGORYSUBID from CT_CUS_PAYITEMSCATE_INIT order by FCATEGORYNUMBER,FCATEGORYSUBCODE,FPAYITEMNUMBER'
cursFrom.execute(sqlStr)
resultFrom = cursFrom.fetchall()
cursTo = connTo.cursor()
#print (i)
sqlInsert = "insert into CT_CUS_PAYITEMSCATE_INIT (FREGIONCODE, FCATEGORYNUMBER, FCATEGORYNAME, FCATEGORYSUBCODE, FCATEGORYSUBNAME, FPAYITEMNUMBER, FPAYITEMNAME, FPAYITETYPE, FCATEGORYID, FCATEGORYSUBID) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"
cursTo.executemany(sqlInsert, resultFrom)

`
Traceback (most recent call last):
File "d:\C\import sys.py", line 29, in
cursTo.executemany(sqlInsert, resultFrom)
File "D:\Programs\Python\Python\lib\site-packages\jaydebeapi_init_.py", line 549, in executemany
self._set_stmt_parms(self.prep, parameters)
File "D:\Programs\Python\Python\lib\site-packages\jaydebeapi_init
.py", line 523, in _set_stmt_parms
prep_stmt.setObject(i + 1, parameters[i])
java.sql.java.sql.SQLException: java.sql.SQLException: Invalid column index

@mikhail5555
Copy link

you have to use ? as injector in your query instead of %s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants