Home > Enterprise >  How to connect to oracle database in Spark using Scala
How to connect to oracle database in Spark using Scala

Time:09-17

I have Spark 3.1.2 and Scala 2.12.8. I want to connect to oracle Database and read a table then show it, using this code:

import org.apache.spark.sql.SparkSession

object readTable extends App{

   val spark = SparkSession
           .builder
           .master("local[*]")
           .appName("Spark SQL basic example")
           .config("spark.some.config.option", "some-value")
           .getOrCreate()

   val jdbcDF = spark.read
           .format("jdbc") 
           .option("url", "jdbc:oracle:thin:@x.x.x.x:1521:orcldb")
           .option("dbtable", "orcl.brnc_grp")
           .option("user", "orcl")
           .option("password", "xxxxxxx")
           .load()

jdbcDF.show()

}
  

When I run the code, I receive this error:

Exception in thread "main" java.sql.SQLException: No suitable driver

Would you please guide me how to solve this problem?

Any help would be really appreciated.

CodePudding user response:

Download oracle JDBC jar from here and place this JAR in $SPARK_HOME/jars folder.

  • Related