【问题标题】:how to update only few columns of a table in spring jdbc template如何在spring jdbc模板中只更新表的几列
【发布时间】:2016-06-03 09:35:17
【问题描述】:

我正在使用 spring jdbc 模板,我想更新表中的一些列。

例如:考虑学生表

id-->1007.
name-->Krish.
age-->25.
tel-->0112538956536.   

这是一个现有记录。我只想更新一些字段(更新字段不时更改)。其他应该有他们现有的值。我如何在 Spring JDBC 模板中实现这一点。任何建议都会非常有帮助。

谢谢。

【问题讨论】:

    标签: spring spring-jdbc


    【解决方案1】:

    您可以使用 jdbc 模板从应用程序更新表

    这是一个简单的例子

    String name = "asdads";
    int age = 12;
    String tel = "+905655465465";
    int id = 1;
    
     String SQL = "update Student set name = ?, age= ? ,tel=?, last_updated = sysdate()  where id = ?";
     jdbcTemplate.update(SQL,name, age, tel, id);
    

    【讨论】:

      【解决方案2】:

      可能就像

      jdbcTemplate.update(
              "update Student set last_updated=now(),some_field=?",
              "some value");
      

      【讨论】:

        猜你喜欢
        • 2019-11-09
        • 1970-01-01
        • 2012-12-15
        • 2019-01-25
        • 1970-01-01
        • 2020-01-04
        • 1970-01-01
        • 2020-05-07
        • 2014-02-08
        相关资源
        最近更新 更多