【问题标题】:Sql Update command used in play framework (scala) does not seem to be working播放框架(scala)中使用的 Sql Update 命令似乎不起作用
【发布时间】:2012-11-06 22:26:18
【问题描述】:

我的 Sql 表设置如下

create table contact(
id                      bigint not null,
first_name                varchar(255) not null,
last_name                 varchar(255) not null,
phone                     varchar(255) not null,
email                     varchar(255) not null,
company                   varchar(255) not null,
external_access           varchar(255),
online_status             varchar(12),
constraint pk_computer primary key (id));

所以最初我将数据值输入到表中,除了 external_access 和 online_status。然后我尝试使用下面的函数更新 online_status。

DB.withConnection { implicit connection =>
SQL(
  """
     update contact
     set online_status = online
     where email = {email}
  """
     ).on(
       'email -> email
         ).executeUpdate()
  } 

所以在线状态更新后,我尝试使用再次显示页面

  select * from contact  

(以上代码只是大意,实际展示功能为https://github.com/playframework/Play20/blob/master/samples/scala/computer-database/app/models/Models.scala的页面展示功能List)

但是,online_status 尚未更新。它继续不显示任何内容(在 online_status 列中)。有人可以帮我调试一下吗

【问题讨论】:

    标签: sql scala jdbc playframework


    【解决方案1】:

    在线状态是一个varchar,你的查询应该是这样的:

     """
         update contact
         set online_status = 'online'
         where email = {email}
      """
    

    注意 '' 将值定义为字符串。

    另外,请确保您没有将旧值存储在缓存中。

    【讨论】:

    • 我尝试了“在线”的东西。没有什么不同。如何确保旧值存储在缓存中?有没有办法检查它并且不允许它发生(可能像 volatile 或其他东西......不太确定)
    猜你喜欢
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    相关资源
    最近更新 更多