Trying to connect to Oracle from Spark

我们两清 提交于 2019-12-04 14:33:16

This one got worked out with this change.

   sqlContext = SQLContext(sc)
   ora_tmp=spark.read.format('jdbc').options(
        url=Oracle_CONNECTION_URL,
        dbtable="tablename",
        driver="oracle.jdbc.OracleDriver"
        ).load() 

I have followed below code and it work for me. Import jdbc drive(ojdbc6).

    import org.apache.spark.sql.SparkSession

    object ConnectingOracleDatabase {
      def main(args: Array[String]): Unit = {
        val spark = SparkSession.builder()
          .appName("ConnectingOracleDatabase")
          .master("local")
          .getOrCreate()

    val jdbcDF = spark.read
      .format("jdbc")
      .option("url", "jdbc:oracle:thin:@localhost:1521:xe")
      .option("dbtable", "ADDRESS")
      .option("user", "system")
      .option("password", "oracle")
      .option("driver", "oracle.jdbc.OracleDriver")
      .load()

    jdbcDF.show()

  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!