在我的 Spark 应用程序中,我尝试使用以下行连接到本地 Postgres 数据库:
val conn = DriverManager.getConnection("jdbc:postgresql://localhost/postgres", "postgres", "*Qwerty#")
Run Code Online (Sandbox Code Playgroud)
Postgres 服务器在端口 5432(默认)上运行。我也尝试过包括端口。我也尝试过Class.forName("org.postgresql.Driver")
,但它抛出 ClassNotFoundException。我已确保驱动程序位于 ClassPath 中。
我正在本地模式下运行 Spark。
但我得到了上述例外。
我已经通过此处提到的方式包含了 jdbc 驱动程序sbt
:
https: //mvnrepository.com/artifact/org.postgresql/postgresql/42.2.2