title: Spark SQL -Problems with saving DataFrame to database through JDBC
body: <p>I have a <code>test</code> table registered from <code>DataFrame</code>using <code>registerTempTable</code>.
  <p>And I query the <code>test</code>table:</p>
  
  <pre><code>df = sqlContext.sql("select no,vipgroupname,sum(name) as count from test group by no,vipgroupname limit 5")
  </code></pre>
  
  <p>Below is the result:
  <p><pre>df.show()
  +---+---------------+----------------------------+
  |no |   vipgroupname|                count       |
  +---+---------------+----------------------------+
  | 1 |       testa   |                         636|
  | 2 |       testb   |                         28 |
  | 3 |       testc   |                         21 |
  | 4 |       testd   |                         142|
  | 5 |       teste   |                         79 |
  +---+---------------+----------------------------+
  </pre></p>
  
  <p>Try to save it as table <code>test</code>to external database (<code>Sybase</code> in this case)</p>
  
  <pre><code>
  
      properties = {
          "user": "test",
          "password": "Test123!"
      }
      url = "jdbc:sybase:Tds:9.16.18.30:5566?ServiceName=test"
      df.write.mode('overwrite').jdbc(url=url, table="test",properties=properties
  
  )
  </code></pre>
  
  <p>This action was all right and the data was all saved to <code>Sybase</code> in table <code>test</code>.
  But when I executed this again to verify the overwrite behavior. </p>
  
  <pre><code>df.write.mode('overwrite').jdbc(url=url, table="test",properties=properties)
  </code></pre>
  
  <p>All I got was the exception:</p>
  
  <pre><code>
  
      Py4JJavaError: An error occurred while calling o547.jdbc.
       java.sql.SQLException: SQL Anywhere Error -110: Item 'test' already exists
          at com.sybase.jdbc4.jdbc.SybConnection.getAllExceptions(SybConnection.java:2780)
          at com.sybase.jdbc4.jdbc.SybStatement.handleSQLE(SybStatement.java:2665)
          at com.sybase.jdbc4.jdbc.SybStatement.nextResult(SybStatement.java:295)
          at com.sybase.jdbc4.jdbc.SybStatement.nextResult(SybStatement.java:272)
          at com.sybase.jdbc4.jdbc.SybStatement.updateLoop(SybStatement.java:2515)
          at com.sybase.jdbc4.jdbc.SybStatement.executeUpdate(SybStatement.java:2499)
          at com.sybase.jdbc4.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:297)
          at org.apache.spark.sql.DataFrameWriter.jdbc(DataFrameWriter.scala:370)
          at sun.reflect.GeneratedMethodAccessor95.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
          at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
          at py4j.Gateway.invoke(Gateway.java:259)
          at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
          at py4j.commands.CallCommand.execute(CallCommand.java:79)
          at py4j.GatewayConnection.run(GatewayConnection.java:207)
          at java.lang.Thread.run(Thread.java:745)
  
    </code></pre>
  
  <p><p> I thought mode <code>overwrite</code> will delete current table and create new table. But this exception seems not the case.
  And the exception came with mode <code>append</code> too. </p>
  
  <p><p>I'm using Jupyter Notebook(installed by <code>Anaconda 5.3.1</code> ) to run above code and Spark version is <code>1.5.1</code>.</p>
  
  <p>Am I using something wrong here?</p>
  
  <p>Thanks!</p>