【发布时间】:2014-03-14 11:33:15
【问题描述】:
我正在使用带有 postgreSQL 的 play 框架,并试图从表中的特定行和列中只获取一个值。 该程序编译代码没有问题,但是当调用带有此代码的操作时,它就不起作用了。 SQL查询工作正常,我在psql中检查过。
DB.withConnection { implicit connection =>
val selectSalt: Option[String] = SQL("""
select salt from devices
where principal_id=(
select id from principals
where principal={id})
""").on(
'id -> user).as(scalar[String].singleOpt)
...(下面还有更多代码)
【问题讨论】:
-
您是否有可能返回多行而不仅仅是 1 行?我认为用户是 Int 还是 Long 来匹配 id?正如其他人所问的那样,您收到的确切错误是什么?
-
我发现我试图获取的值是空的,我填写了它并且代码有效。但是为什么它在 null 时不起作用?
-
如果值为空,
selectSalt应该包含一个None。不知道为什么它没有执行你的 println。
标签: sql database postgresql scala playframework