通过 Databricks 在 db2 中对表进行批量更新

问题描述 投票:0回答:1

下面是代码......

from datetime import datetime, date
def update_chk_table(ENV, notebook_name, df):
    # Create a connection object using a jdbc-url, + sql uname & pass
    connection = spark._jvm.java.sql.DriverManager.getConnection(url, user, password)
    connection.setAutoCommit(False)
    statement = connection.prepareStatement(
        """update CPYDB01.CHK 
           SET CHK_UPD_USR = ? and CHK_MSG_LN = ? 
           WHERE CHK_NBR = ? AND BANK_ACCT_NBR  = ? AND BANK_ABA_NBR = ? AND CHK_ISS_DT = ?"""
        )
    try:
        # loop through the dataframe and add batch updates
        for row in filter_fpdb_reisstyp_df.collect():
  
        statement.setString(1, chk_upd_usr_value)
        statement.setString(2, chk_msg_ln_value)
        statement.setBigDecimal(3, spark._jvm.java.math.BigDecimal(str(row['CHK_NBR']))) 
        statement.setBigDecimal(4, spark._jvm.java.math.BigDecimal(str(row['BANK_ACCT_NBR']))) 
        statement.setBigDecimal(5, spark._jvm.java.math.BigDecimal(str(row['BANK_ABA_NBR'])))
        statement.setDate(6, chk_iss_dt_str) #Where condition CHK_ISS_DT
        statement.addBatch()

执行时我面临问题。附上问题参考截图:

When executed I am facing issue. so attached is the screenshot for issue reference

我尝试通过 Databricks 对 db2 中的表进行批量更新。我的期望是表格在我作为参数传递的数据帧中的所有记录的两列上进行更新。

python pyspark db2 databricks
1个回答
0
投票

查看如何在 SQL 中完成 update

在 Set 子句中,各列需要用逗号分隔,并且不能用“and”组合

© www.soinside.com 2019 - 2024. All rights reserved.