import scala.slick.driver.PostgresDriver.simple._
import scala.slick.session.Database.threadLocalSession
object Main extends App {
Database.forURL("jdbc:postgresql://localhost:5432/slick", driver =
"org.postgresql.Driver",user="postgres",password="postgres") withSession { } ;
}
我想填写“withSession”参数是什么?我正在尝试使用灵活的教程here,但是使用postgres。
这是我的错误堆栈:
> run
[info] Running Main
[error] (run-main) java.sql.SQLException: No implicit session available; threadLocalSession can only be used within a withSession block
java.sql.SQLException: No implicit session available; threadLocalSession can only be used within a withSession block
at scala.slick.session.Database$.threadLocalSession(Database.scala:74)
at Main$delayedInit$body.apply(main.scala:9)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at Main$.main(main.scala:4)
at Main.main(main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 0 s, completed Sep 19, 2013 3:38:34 PM
谢谢!
答案 0 :(得分:5)
withSession是您查询的地方。他们需要一个会议。另外请删除threadLocalSession导入,然后写入
withSession{ implicit session:Session =>
// <- your queries here
}