[英]Scala Anorm Select Query
With the following DB script: 使用以下数据库脚本:
# Tasks schema
# --- !Ups
CREATE TABLE HashToUrl (
hash integer,
url varchar(255)
);
# --- !Downs
DROP TABLE HashToUrl;
... why do I get this error: ...为什么会出现此错误:
[NoSuchElementException: key not found: hash]
[NoSuchElementException:找不到密钥:哈希]
... for this method ...对于这种方法
def getTask(hash: Int): String = DB.withConnection { implicit c =>
val result = SQL(
"""
select count(*) as url from HashToUrl where hash={hash}
"""
).apply().head
val url = result[String]("url")
url
}
your code doesn't contain anything that will substitute the hash variable into the format string. 您的代码不包含任何将哈希变量替换为格式字符串的内容。
here are some very simple anorm examples to help you see what to do: 以下是一些非常简单的主动脉瘤示例,可帮助您了解该怎么做:
https://github.com/dustingetz/orm-deep-dive/blob/master/app/models/Environment.scala https://github.com/dustingetz/orm-deep-dive/blob/master/app/models/Environment.scala
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.