title: Check table exists Spark jdbc
body: <p>I am reading some data into a data frame from Microsoft SQL server using Spark JDBC. And when the table does not exist (for example, it was dropped accidentally) I get an exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'TestAllData'.</p>
  
  <p>I would like to create some mechanism to check first whether the table exists and only then read the data. Is there a way to do that using Spark JDBC?
  Because I tried using if exists construct from Ms sql server, but it does not work for querying with Spark. </p>
  
  <p>Currently, my code for reading the data looks like this:</p>
  
  <pre><code>     def getDataQuery() = {
      s"(select * from TestData) as subq"
    }
  
  
  def jdbcOptions(dataQuery: String, partitionColumn: String, lowerBound: String, upperBound: String, numPartitions: String) = Map[String,String](
      "driver" -&gt; config.getString("sqlserver.db.driver"),
      "url" -&gt; config.getString("sqlserver.db.url"),
      "user" -&gt; config.getString("sqlserver.db.user"),
      "password" -&gt; config.getString("sqlserver.db.password"),
      "customSchema" -&gt; config.getString("sqlserver.db.custom_schema"),
      "dbtable" -&gt; dataQuery,
      "partitionColumn" -&gt; partitionColumn,
      "lowerBound" -&gt; lowerBound,
      "upperBound" -&gt; upperBound,
      "numPartitions" -&gt; numPartitions
    )
  
      val dataDF = sparkSession
        .read
        .format("jdbc")
        .options(jdbcOptions(getDataQuery()))
        .load()
  </code></pre>