我正在尝试用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"
)发布于 2015-10-06 22:10:09
尝试将driverName添加到如下设置:
val settings = ConnectionPoolSettings(
initialSize = 10,
maxSize = 10,
connectionTimeoutMillis = 3000L,
driverName = "org.postgresql.Driver")
ConnectionPool.singleton(url, user, pass, settings)https://stackoverflow.com/questions/30979445
复制相似问题