title: spark.read is not a member of package org.apache.spark
body: <p>I'm trying to connect postgresql and spark on Intellij. However I'm getting <code>object read is not a member of package org.apache.spark</code> error even though I've included JDBC driver in my build.sbt.</p>
  
  <p>I'm trying to follow this tutorial <a href="https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html" rel="nofollow noreferrer">https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html</a> and here is my scala code:</p>
  
  <pre class="lang-scala prettyprint-override"><code>import org.apache.spark
  
  object DBConn {
  
    def main(args: Array[String]): Unit = {
  
      // Note: JDBC loading and saving can be achieved via either the load/save or jdbc methods
      // Loading data from a JDBC source
      val jdbcDF = spark.read
        .format("jdbc")
        .option("url", "jdbc:postgresql://host/db")
        .option("dbtable", "chroniker_log")
        .option("user", "username")
        .option("password", "password")
        .load()
  
      val connectionProperties = new Properties()
      connectionProperties.put("user", "username")
      connectionProperties.put("password", "password")
      val jdbcDF2 = spark.read
        .jdbc("jdbc:postgresql:dbserver", "schema.tablename", connectionProperties)
      // Specifying the custom data types of the read schema
      connectionProperties.put("customSchema", "id DECIMAL(38, 0), name STRING")
      val jdbcDF3 = spark.read
        .jdbc("jdbc:postgresql:dbserver", "schema.tablename", connectionProperties)
    }
  }
  </code></pre>
  
  <p>build.sbt:</p>
  
  <pre><code>name := "DBConnect"
  
  version := "0.1"
  
  scalaVersion := "2.11.12"
  
  val sparkVersion = "2.4.3"
  
  resolvers ++= Seq(
    "apache-snapshots" at "http://repository.apache.org/snapshots/"
  )
  
  libraryDependencies ++= Seq(
    "org.apache.spark" %% "spark-core" % sparkVersion,
    "org.postgresql" % "postgresql" % "42.2.5"
  )
  </code></pre>
  
  <p>I tried to simplify the problem by running spark-shell on the console. However, this following command also throws the same warning:</p>
  
  <pre><code>spark-shell --driver-class-path postgresql-42.2.5.jar --jars postgresql-42-2.5.jar -i src/main/scala/DBC
  onn.scala
  </code></pre>
  
  <p>interestingly once I'm in spark-shell after the above code fail, it starts recognizing <code>spark.read</code> and successfully connects to the database.</p>