jaydebeapi executemany() 方法不适用于仅包含一个参数的 sql 查询,但同时两个参数可以正常工作。
例如给定的查询不执行:
cursor.executemany("DELETE FROM table1 WHERE col1 = ?", tup_df)
这个工作正常
cursor.executemany("DELETE FROM table1 WHERE col1 = ? AND col2 = ?", tup_df)
假设后面的表达式AND
使用数据库中的现有列进行操作(使用一些类似的变通方法1 = ?
没有成功)
使用第一种情况测试代码
df = pandas.DataFrame(data={'col1': [3563412]})
conn = jaydebeapi.connect(jar_class, url, {'user': user, 'password': password}, jar_path)
cursor = conn.cursor()
row_count = 0
for _, df in df.groupby(np.arange(len(df)) // 2000):
tup_df = [tuple(x) for x in df.values]
cursor.executemany("DELETE FROM table1 WHERE col1 = ?", tup_df)
row_count = row_count + cursor.rowcount
print(row_count + ' row(s) processed')
第二种情况的测试代码
df = pandas.DataFrame(data={'col1': [3563412]})
conn = jaydebeapi.connect(jar_class, url, {'user': user, 'password': password}, jar_path)
cursor = conn.cursor()
row_count = 0
for _, df in df.groupby(np.arange(len(df)) // 2000):
tup_df = [tuple(x) for x in df.values]
cursor.executemany("DELETE FROM table1 WHERE col1 = ? AND col2 = ?", tup_df)
row_count = row_count + cursor.rowcount
print(row_count + ' row(s) processed')
投掷错误:
Traceback (most recent call last):
File "test.py", line 21, in <module>
cursor.executemany("DELETE FROM table1 WHERE col1 = ?", tup_df)
File "/home/ray/.local/lib/python3.6/site-packages/jaydebeapi/__init__.py", line 516, in executemany
self._set_stmt_parms(self._prep, parameters)
File "/home/ray/.local/lib/python3.6/site-packages/jaydebeapi/__init__.py", line 490, in _set_stmt_parms
prep_stmt.setObject(i + 1, parameters[i])
RuntimeError: No matching overloads found for setObject in find. at native/common/jp_method.cpp:127
当前数据库是 db2,jaydebeapi - 1.1.1,jpype - 0.6.3,python - 3.6。更改数据库没有帮助。任何帮助将不胜感激。