1
我試圖使用anorm庫將對象保存到play2 webapp中的postgresql Db中。 在創建表「地址」的說法,這是一個:在playgresql框架中使用anorm在postgresql數據庫中保留對象2
create table address (
addressId bigserial not null,
addressName varchar(255) not null,
street varchar(255) not null,
number varchar(15) not null,
ZIP varchar(15) not null,
region varchar(63) not null,
country varchar(63) not null,
constraint pk_address primary key (addressId)
);
我的斯卡拉/ ANORM代碼如下所示:
private def create(address: Address, recursive : Boolean): Long = {
DB.withConnection { implicit connection =>
SQL("""
insert into {table_name} (addressName, street, number, ZIP, region, country)
values ({name},{street},{number},{ZIP},{region},{country})
""").on(
"table_name" -> TABLE_NAME,
"name" -> address.name,
"street" -> address.street,
"number" -> address.number,
"ZIP" -> address.ZIP,
"region" -> address.region,
"country"-> address.country
).executeInsert[Option[Long]]().get
}
}
顯然TABLE_NAME是包含字符串VAL「地址」
的問題是,當我打算用適當的Address實例執行:
Address("Antonio","vacchi","12","48012","RA","Italia")
我得到這個異常:
[PSQLException: ERROR: syntax error at or near "$1" Posizione: 13]
「Posizione」是位置上的字意(說不上來爲什麼我得到了意大利Ø:)
你保存了我的白天/夜晚;) 不知道爲什麼我沒有想到它像一個準備好的語句的包裝;)謝謝! – tmnd91