首页 > 解决方案 > 带有方法 setProperty 错误的 PySpark jdbc 错误

问题描述

将数据写入 oracle 数据库时遇到以下错误。我面临以下奇怪的错误。

我不确定下面的问题是代码

 self.batchsize = 50000
 self.tgt_url = 'jdbc:oracle:thin:@' + self.tgt_hostname + ":" + self.tgt_port + "/" + self.tgt_schema
 self.tgt_connectionProperties = {"user": self.tgt_username, "password": self.tgt_password,"driver": "oracle.jdbc.driver.OracleDriver", "batchszie": self.batchsize}
 temp_table = self.TgtDatabase + "." + self.TgtTable
 self.inmemdf.write.jdbc(self.tgt_url, table = temp_table , mode='append', properties=self.tgt_connectionProperties)

    An error occurred while calling o171.setProperty. Trace:
    py4j.Py4JException: Method setProperty([class java.lang.String, class java.lang.Integer]) does not exist
        at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
        at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
        at py4j.Gateway.invoke(Gateway.java:274)
        at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
        at py4j.commands.CallCommand.execute(CallCommand.java:79)
        at py4j.GatewayConnection.run(GatewayConnection.java:238)
        at java.lang.Thread.run(Thread.java:748)

我最初认为这是数据问题,甚至还将数据转换为目标数据类型。无法理解这是什么类型的错误

标签: pythonoracleapache-sparkjdbcpyspark

解决方案


  1. 您的代码中有错字"batchszie": self.batchsize,应该是"batchsize": self.batchsize
  2. self.batchsize是Integer类型的,而错误说没有(String,Integer)的方法,所以只需将其更改为String:
self.batchsize = '50000'

推荐阅读