【发布时间】:2014-04-21 07:38:40
【问题描述】:
我需要将数组数据存储到数据库中。但我没有找到如何做到这一点的样本。我尝试将数组视为普通数据类型,但它似乎不起作用。这是我的代码:
在数据库表中,我有 3 列:
Id integer,
uLocation integer,
Prices integer(366)
在 SQL 中,使用以下方法插入、更新或查询表:
def InseartToDatabase(ItemPrices: ListBuffer[Int], Id: Int, uLocation: Int) = {
val prices = ItemPrices.toArray
DB.withConnection { implicit c =>
SQL("insert into task (Id, uLocation, Prices) values ({Id},{uLocation}, {Prices})").on('Id ->Id, 'uLocation->uLocation, 'Prices -> Prices).executeUpdate()
}
}
这不能静默工作,也不会报告异常。但是下一次更新失败了。如果我删除数组字段,上面的代码就可以正常工作。
另外,我不知道如何查询它。
【问题讨论】:
标签: sql arrays scala playframework-2.0 anorm