0
votes

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]

... 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
}
1

1 Answers

1
votes

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