title: Fill an empty postgres database in Pyspark
body: <p>I would like to put a Pyspark dataframe <code>json_df</code> into a totally empty postgres database (no schema and table). I use the following code but there is something wrong with the table selected in the option of the write statement. The error shows a driver issue but I have the driver updated so I assume it is just my code which is wrong. Any help would be appreciated.</p>
  <p>My code:</p>
  <pre><code>database = &quot;postgres&quot;
  
  jdbcUrl = f&quot;jdbc:postgres://localhost:5432;databaseName={database}&quot;
  
  schema = StructType([
    StructField('first_column', StringType(), True),
    StructField('second_columns', StringType(), True),
    ])
  df = sqlContext.createDataFrame(sc.emptyRDD(),schema)
  
  json_df.select(&quot;first_column&quot;,&quot;second_column&quot;).write.format(&quot;jdbc&quot;) \
    .mode(&quot;overwrite&quot;) \
    .option(&quot;url&quot;, jdbcUrl) \
    .option(&quot;user&quot;, user) \
    .option(&quot;dbtable&quot;, df) \
    .save()
  </code></pre>
  <p>The error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;etl.py&quot;, line 98, in &lt;module&gt;
      .option(&quot;dbtable&quot;, df) \
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/pyspark/sql/readwriter.py&quot;, line 825, in save
      self._jwrite.save()
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/py4j/java_gateway.py&quot;, line 1305, in __call__
      answer, self.gateway_client, self.target_id, self.name)
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/pyspark/sql/utils.py&quot;, line 128, in deco
      return f(*a, **kw)
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/py4j/protocol.py&quot;, line 328, in get_return_value
      format(target_id, &quot;.&quot;, name), value)
  py4j.protocol.Py4JJavaError: An error occurred while calling o74.save.
  : java.sql.SQLException: No suitable driver
  </code></pre>
  <p>Edit:</p>
  <p>After changing the code to:</p>
  <pre><code>json_df.write.format(&quot;jdbc&quot;) \
    .mode(&quot;overwrite&quot;) \
    .option(&quot;url&quot;, jdbcUrl) \
    .option(&quot;user&quot;, user) \
    .option(&quot;dbtable&quot;, &quot;news_schema.json_df&quot;) \
      .save()
  </code></pre>
  <p>The error is:</p>
  <pre><code> File &quot;etl.py&quot;, line 104, in &lt;module&gt;
      .option(&quot;dbtable&quot;, &quot;new_schema.json_df&quot;) \
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/pyspark/sql/readwriter.py&quot;, line 825, in save
      self._jwrite.save()
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/py4j/java_gateway.py&quot;, line 1305, in __call__
      answer, self.gateway_client, self.target_id, self.name)
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/pyspark/sql/utils.py&quot;, line 128, in deco
      return f(*a, **kw)
    File &quot;/home/ubuntu/.local/lib/python3.6/site-packages/py4j/protocol.py&quot;, line 328, in get_return_value
      format(target_id, &quot;.&quot;, name), value)
  py4j.protocol.Py4JJavaError: An error occurred while calling o53.save.
  : java.sql.SQLException: No suitable driver
  </code></pre>