gpt4 book ai didi

postgresql - scalikeJDBC + postgres - 找不到合适的驱动程序

转载 作者:行者123 更新时间:2023-11-29 13:27:38 25 4
gpt4 key购买 nike

我正在尝试使用 scalikeJDBC 连接到 postgres

我有以下错误信息:

An exception or error caused a run to abort: No suitable driver found for jdbc:postgresql://localhost:5432 
java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432

我的做法是:

import org.scalatest.{Matchers, FlatSpec}
import scalikejdbc._
import org.postgresql.Driver._
import grpn.Opportunity

class testDBconnection extends FlatSpec with Matchers {

println(System.getProperty("java.class.path"))
// initialize JDBC driver & connection pool
Class.forName("org.postgresql.Driver")
ConnectionPool.singleton("jdbc:postgresql://localhost:5432/dbname", "postgres", "pwd")

// ad-hoc session provider on the REPL
implicit val session = AutoSession

// table creation, you can run DDL by using #execute as same as JDBC
object AClass extends SQLSyntaxSupport[AClass] {
def apply(rs: WrappedResultSet) = new AClass(
rs.string("blahblah"),
....

)
}

val res: List[AClass] =
sql"""
SELECT *
FROM tablename
""".map(e => AClass(e)).list.apply()

}

我已经检查过,..\cache\org.postgresql\postgresql\jars\postgresql-9.4-1200-jdbc41.jar 出现在类路径中。

在我的 build.sbt 中:

libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test",
"org.scalanlp" %% "breeze" % "0.11.2" % "test",
"org.scalikejdbc" %% "scalikejdbc" % "2.2.7",
"org.postgresql" % "postgresql" % "9.4-1200-jdbc41"
)

最佳答案

尝试将 driverName 添加到设置中,如下所示:

  val settings = ConnectionPoolSettings(
initialSize = 10,
maxSize = 10,
connectionTimeoutMillis = 3000L,
driverName = "org.postgresql.Driver")

ConnectionPool.singleton(url, user, pass, settings)

关于postgresql - scalikeJDBC + postgres - 找不到合适的驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30979445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com