title: pyspark to read data from sql server
body: <p>I'm trying to read data from sql server using pyspark. Below mentioned code works fine when executed using following command (where i'm passing sqljdbc driver path) but it fails when i try to run it using PyCharm IDE(on windows).</p>
  
  <pre><code>spark-submit --driver-class-path C:\drivers\sqljdbc_6.0.8112.100_enu\sqljdbc_6.0\enu\jre8\sqljdbc42.jar ReadSQLServerData.py
  </code></pre>
  
  <p>How to include or set the driver path while running same code through PyCharm IDE?</p>
  
  <p>Code:</p>
  
  <pre><code>from pyspark.sql import SQLContext, Row
  from pyspark import SparkConf, SparkContext
  
  conf = SparkConf().setAppName("ReadSQLServerData")
  sc = SparkContext(conf=conf)
  query = "(SELECT top 10 * from users) as users"
  sqlctx = SQLContext(sc)
  
  df = sqlctx.read.format("jdbc").options(url="jdbc:sqlserver://mssqlserver:1433;database=user_management;user=pyspark;password=pyspark", dbtable=query).load()
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>Traceback (most recent call last):
    File "H:/Mine/OneDrive/Python/PySpark01/ReadSQLServerData.py", line 9, in &lt;module&gt;
      df = sqlctx.read.format("jdbc").options(url="jdbc:sqlserver://mssqlserver:1433;database=user_management;user=pyspark;password=pyspark", dbtable=query).load()
    File "C:\spark\python\pyspark\sql\readwriter.py", line 155, in load
      return self._df(self._jreader.load())
    File "C:\spark\python\lib\py4j-0.10.4-src.zip\py4j\java_gateway.py", line 1133, in __call__
    File "C:\spark\python\pyspark\sql\utils.py", line 63, in deco
      return f(*a, **kw)
    File "C:\spark\python\lib\py4j-0.10.4-src.zip\py4j\protocol.py", line 319, in get_return_value
  py4j.protocol.Py4JJavaError: An error occurred while calling o27.load.
  : java.sql.SQLException: No suitable driver
      at java.sql.DriverManager.getDriver(DriverManager.java:315)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$7.apply(JDBCOptions.scala:84)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$7.apply(JDBCOptions.scala:84)
      at scala.Option.getOrElse(Option.scala:121)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.&lt;init&gt;(JDBCOptions.scala:83)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.&lt;init&gt;(JDBCOptions.scala:34)
      at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:32)
      at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:330)
      at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152)
      at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:125)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
      at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
      at py4j.Gateway.invoke(Gateway.java:280)
      at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
      at py4j.commands.CallCommand.execute(CallCommand.java:79)
      at py4j.GatewayConnection.run(GatewayConnection.java:214)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>