0

我对以下 JDBC 错误感到困惑。

[JdbcSQLException:未找到列“HASH”;SQL 语句:插入 HashToUrl (hash, url) 值 (hash, url) [42122-158]]

1.sql

# Tasks schema

# --- !Ups

CREATE TABLE HashToUrl  (
    Hash integer,
    Url  varchar(255)
);

# --- !Downs

DROP TABLE HashToUrl;

我的插入语句不好吗?

模型/Task.scala

def create(hash: Int, url:String) {
    DB.withConnection { implicit c =>
        SQL("insert into HashToUrl (hash, url) values ({hash, url})")
        .executeUpdate()
    }
}
4

3 回答 3

0

I don't use Anorm, but I don't think it automatically binds data to parameter.

SQL("insert into HashToUrl (hash, url) values ({hash, url})")
    .on("hash" -> hash, "url" -> url)
    .executeUpdate()

(I don't think it's your current error, check character case like said nico)

于 2013-01-05T13:23:09.777 回答
0

您使用的是哪个数据库?例如,PostgreSQL 区分大小写。如果是这样,您应该在 SQL 中指定不是“哈希”而是“哈希”。

SQL("insert into HashToUrl (Hash, Url) values ({hash, url})")...
于 2013-01-06T16:11:28.977 回答
0
SQL("insert into HashToUrl (hash, url) values ({hash, url})")
    .executeUpdate()

应该

SQL("insert into HashToUrl (hash, url) values ({hash, url})").on('hash -> hash, 'url-> url).executeUpdate()
于 2013-01-07T11:39:51.317 回答