title: spark sql error while querying sql server table
body: <p>Error while trying to query sql server table please help.</p>
  
  <p>Specifying database name or other qualifiers are not allowed for temporary tables. If the table name has dots (.) in it, please quote the table name with backticks (`).;</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  val sqlContext = new org.apache.spark.sql.SQLContext(sc)
        val querytest=sqlContext.sql(query)
        val prop=new Properties()
        val url2="jdbc:sqlserver://localhost;user=admin;password=oracle;database=AdventureWorks2014"
        prop.setProperty("user","admin")
        prop.setProperty("password","oracle")
        val test=sqlContext.read.jdbc(url2,"Customer",prop)</code></pre>
  </div>
  </div>
  </p>
  
  <p>Made changes to the code which worked:-</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package com.kali.db
  
  /**
   * Created by kalit_000 on 06/12/2015.
   */
  
  import java.util.Properties
  import org.apache.spark.SparkConf
  import org.apache.log4j.Logger
  import org.apache.log4j.Level
  import org.apache.spark._
  import org.apache.spark.rdd.{JdbcRDD, RDD}
  import org.apache.spark.sql.DataFrame
  import org.springframework.context.support.ClassPathXmlApplicationContext
  
  case class SparkSqlValueClassMPP(driver:String,url:String,username:String,password:String,table:String,opdelimeter:String,lowerbound:String,upperbound:String,numberofparitions:String,parallelizecolumn:String)
  
  object SparkDBExtractorMPP {
  
    def main (args: Array[String]) {
  
      Logger.getLogger("org").setLevel(Level.WARN)
      Logger.getLogger("akka").setLevel(Level.WARN)
  
      val conf = new SparkConf().setMaster("local[*]").setAppName("SparkDBExtractorMPP").set("spark.hadoop.validateOutputSpecs", "false")
      val sc = new SparkContext(conf)
  
      def opfile(value:DataFrame,delimeter:String):RDD[String]=
      {
        value.map(x =&gt; x.toString.replace("[","").replace("]","").replace(",",delimeter))
      }
  
      //read the application context file
      val ctx = new ClassPathXmlApplicationContext("sparkDBExtractorMpp.xml")
      val DBinfo = ctx.getBean("SparkSQLDBExtractorMPP").asInstanceOf[SparkSqlValueClassMPP]
  
      val driver = DBinfo.driver
      val url = DBinfo.url
      val username = DBinfo.username
      val password = DBinfo.password
      val table = DBinfo.table
      val opdelimeter=DBinfo.opdelimeter
      val lowerbound=DBinfo.lowerbound.toInt
      val upperbound=DBinfo.upperbound.toInt
      val numberofpartitions=DBinfo.numberofparitions.toInt
      val parallelizecolumn=DBinfo.parallelizecolumn
  
  
      println("DB Driver:-%s".format(driver))
      println("DB Url:-%s".format(url))
      println("Username:-%s".format(username))
      println("Password:-%s".format(password))
      println("Table:-%s".format(table))
      println("Opdelimeter:-%s".format(opdelimeter))
      println("Lowerbound:-%s".format(lowerbound))
      println("Upperbound:-%s".format(upperbound))
      println("Numberofpartitions:-%s".format(numberofpartitions))
      println("Parallelizecolumn:-%s".format(parallelizecolumn))
  
      try {
      val props=new Properties()
      props.put("user",username)
      props.put("password",password)
      props.put("driver",driver)
  
      val sqlContext = new org.apache.spark.sql.SQLContext(sc)
      val df = sqlContext.read.jdbc(url,table,parallelizecolumn,lowerbound,upperbound,numberofpartitions,props)
  
      df.show(10)
  
      opfile(df,opdelimeter).saveAsTextFile("C:\\Users\\kalit_000\\Desktop\\typesafe\\scaladbop\\op.txt")
  
      } catch {
        case e: Exception =&gt; e.printStackTrace
      }
      sc.stop()
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am using Spring bean to make spark code configurable </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
          "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  &lt;beans&gt;
      &lt;bean id="queryProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;
      &lt;/bean&gt;
  
      &lt;bean id="SparkSQLDBExtractorMPP" class="com.kali.db.SparkSqlValueClassMPP"&gt;
          &lt;constructor-arg value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /&gt;
          &lt;constructor-arg value="jdbc:sqlserver://localhost;user=admin;password=oracle;database=AdventureWorks2014" /&gt;
          &lt;constructor-arg value="admin" /&gt;
          &lt;constructor-arg value="oracle" /&gt;
          &lt;constructor-arg value="(select top 100 CustomerID,StoreID,TerritoryID,AccountNumber,ModifiedDate from customer ) as customer" /&gt;
          &lt;constructor-arg value="~" /&gt;
          &lt;constructor-arg value="1" /&gt;
          &lt;constructor-arg value="100" /&gt;
          &lt;constructor-arg value="8" /&gt;
          &lt;constructor-arg value="CustomerID" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;</code></pre>
  </div>
  </div>
  </p>