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

时间:2015-06-22 11:58:41

标签: postgresql scala

我正在尝试使用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"
)

1 个答案:

答案 0 :(得分:1)

尝试将driverName添加到以下设置中:

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

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