Spark:java.sql.SQLException:找不到适用于jdbc:postgresql://localhost/postgres的驱动程序 [英] Spark : java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost/postgres
问题描述
在我的spark应用程序中,我尝试使用以下行连接到本地Postgres数据库:
In my spark application, I am trying to connect to local Postgres database using following line:
val conn = DriverManager.getConnection("jdbc:postgresql://localhost/postgres", "postgres", "*Qwerty#")
Postgres服务器在端口5432上运行(默认).我也尝试过包括港口.
我也尝试过Class.forName("org.postgresql.Driver")
,但是它抛出ClassNotFoundException.我已经确定驱动程序在ClassPath中.
Postgres server is running on port 5432 (default). I have also tried including the port.
I have also tried Class.forName("org.postgresql.Driver")
but it throws ClassNotFoundException. I have made sure that the driver is in the ClassPath.
我在本地模式下运行spark.
I am running spark in the local mode.
但是我遇到了以上异常.
But I am getting the above exception.
我已经通过sbt
包含了jdbc驱动程序,如此处所述:
https://mvnrepository.com/artifact/org.postgresql/postgresql/42.2. 2
I have included the jdbc driver via sbt
as mentioned here :
https://mvnrepository.com/artifact/org.postgresql/postgresql/42.2.2
推荐答案
因此,问题在于执行者无法访问驱动程序jar.
So the problem was executors were not able to access the driver jar.
因此使用spark.jars
配置属性传递驱动程序jar即可解决该问题.
So passing driver jar using spark.jars
configuration property solved it.
在spark文档中此处:
以逗号分隔的jar列表,包括在驱动程序和执行程序上 类路径.允许使用globs.
Comma-separated list of jars to include on the driver and executor classpaths. Globs are allowed.
这篇关于Spark:java.sql.SQLException:找不到适用于jdbc:postgresql://localhost/postgres的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!