Exception in thread "main" java.lang.ClassNotFoundException: Could not load an Amazon Redshift JDBC driver
See original GitHub issueTrying to run the below in Intellij (without using spark-submit and adding the jdbc postgres jar file with --jars flag). I have the below basic code to test out a connection to redshift but getting the below error.
import org.apache.spark.sql._
import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}
object RedshiftTest {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setAppName("Test").setMaster("local[*]")
val sc = new SparkContext(sparkConf)
val sqlContext = new SQLContext(sc)
val jdbcURL = "jdbc:redshift://<host>:5439/<db>?user=<username>&password=<pass>"
val tempS3Dir = "s3a://<bucket>/spark_redshift_out/"
val hadoopConf =sc.hadoopConfiguration
hadoopConf.set("fs.s3a.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")
hadoopConf.set("fs.s3a.awsAccessKeyId", "<key>")
hadoopConf.set("fs.s3a.awsSecretAccessKey", "<secret>")
// Get some data from a Redshift table
val df: DataFrame = sqlContext.read
.format("com.databricks.spark.redshift")
.option("url", jdbcURL)
.option("dbtable", "<table>")
.option("tempdir", tempS3Dir)
.load()
println(df.show())
}
Exception in thread "main" java.lang.ClassNotFoundException: Could not load an Amazon Redshift JDBC driver; see the README for instructions on downloading and configuring the official Amazon driver.
at com.databricks.spark.redshift.JDBCWrapper$$anonfun$getDriverClass$1.apply(RedshiftJDBCWrapper.scala:80)
at com.databricks.spark.redshift.JDBCWrapper$$anonfun$getDriverClass$1.apply(RedshiftJDBCWrapper.scala:70)
at scala.Option.getOrElse(Option.scala:121)
at com.databricks.spark.redshift.JDBCWrapper.getDriverClass(RedshiftJDBCWrapper.scala:69)
at com.databricks.spark.redshift.JDBCWrapper.getConnector(RedshiftJDBCWrapper.scala:205)
at com.databricks.spark.redshift.RedshiftRelation$$anonfun$schema$1.apply(RedshiftRelation.scala:63)
at com.databricks.spark.redshift.RedshiftRelation$$anonfun$schema$1.apply(RedshiftRelation.scala:60)
at scala.Option.getOrElse(Option.scala:121)
at com.databricks.spark.redshift.RedshiftRelation.schema$lzycompute(RedshiftRelation.scala:60)
at com.databricks.spark.redshift.RedshiftRelation.schema(RedshiftRelation.scala:59)
at org.apache.spark.sql.execution.datasources.LogicalRelation.<init>(LogicalRelation.scala:39)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:130)
at com.sparkexamples.RedshiftTest$.main(RedshiftTest.scala:30)
at com.sparkexamples.RedshiftTest.main(RedshiftTest.scala)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: com.amazon.redshift.jdbc4.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.databricks.spark.redshift.Utils$.classForName(Utils.scala:42)
at com.databricks.spark.redshift.JDBCWrapper$$anonfun$getDriverClass$1.apply(RedshiftJDBCWrapper.scala:77)
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Pyspark - configure Amazon Redshift JDBC jar - Stack Overflow
lang.ClassNotFoundException: Could not load an Amazon Redshift JDBC driver; see the README for instructions on downloading and configuring the ...
Read more >Error Connecting with New Redshift JDBC Drivers : DBE-1142
Then, when attempting to run a query, I receive a "Exception in thread "main" java.lang.ClassNotFoundException: org.postgresql.Driver" error.
Read more >Download the Amazon Redshift JDBC driver, version 2.1
This ZIP file contains the JDBC 4.2–compatible driver version 2.1 and AWS SDK for Java 1.x driver–dependent library files. Unzip the dependent jar...
Read more >How to Fix java.lang.ClassNotFoundException: com.mysql ...
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Solution in Maven · 1. Select pom. · 2. Go to the dependency tab as shown below · 3. Click add...
Read more >com.amazon.redshift.jdbc41.Driver]]" while running ... - Search
"Test Connection Failed.[SDK_APP_COM_20000]error [[SDK_APP_COM_20000] error [java.lang.ClassNotFoundException: com.amazon.redshift.jdbc41.Driver]]" while ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue here @JoshRosen 😦 Not sure what I’m doing wrong. I’m running spark within docker with jupyter. – the pyspark. I can access aws s3 and redshift fine without spark, so its not a permission issue. Using these commands:
I get error:
does this also support java ?