title: How to connect (Py)Spark to Postgres database using JDBC
body: <p>I have followed instructions from <a href="https://stackoverflow.com/questions/30983982/how-to-use-jdbc-source-to-write-and-read-data-in-pyspark">this posting</a> to read data from an existing Postgres database with table named "objects" as defined and created by the <code>Objects</code> class in SQLalchemy. In my Jupyter notebook, my code is</p>
  
  <pre><code>from pyspark import SparkContext
  from pyspark import SparkConf
  from random import random
  
  #spark conf
  conf = SparkConf()
  conf.setMaster("local[*]")
  conf.setAppName('pyspark')
  
  sc = SparkContext(conf=conf)
  
  from pyspark.sql import SQLContext
  sqlContext = SQLContext(sc)
  properties = {
      "driver": "org.postgresql.Driver"
  }
  url = 'jdbc:postgresql://PG_USER:PASSWORD@PG_SERVER_IP/db_name'
  df = sqlContext.read.jdbc(url=url, table='objects', properties=properties)
  </code></pre>
  
  <p>the last line results in the following:</p>
  
  <pre><code>Py4JJavaError: An error occurred while calling o25.jdbc.
  : java.lang.NullPointerException
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:158)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation.&lt;init&gt;(JDBCRelation.scala:117)
      at org.apache.spark.sql.DataFrameReader.jdbc(DataFrameReader.scala:237)
      at org.apache.spark.sql.DataFrameReader.jdbc(DataFrameReader.scala:159)
      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:237)
      at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
      at py4j.Gateway.invoke(Gateway.java:280)
      at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:128)
      at py4j.commands.CallCommand.execute(CallCommand.java:79)
      at py4j.GatewayConnection.run(GatewayConnection.java:211)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>so it looks like it can't resolve the table. How do I test from here to make sure that I am connected to the database properly?</p>