[英]Update Query using Spring JDBC
I am trying to build an update query - For example 我正在尝试建立更新查询-例如
update table A set Column 1 = ,Column 2= , Column 3..... where
Constant selection criteria
Lets says max number of columns that is to be updated is 3 and there can be any set of combination depending upon some business rule , For example 假设要更新的最大列数为3,并且可以根据某些业务规则进行任意组合,例如
Condition 1 - update only Column 1
Condition 2 - update Column 1 and Column 2 and so on. ( 6 combinations in this case)
How would your approach be , to build update Query in this case ? 在这种情况下,如何构建更新查询?
I am NOT using Hibernate . 我没有使用Hibernate。
I can think of crude way to build queries only. 我可以想到仅用于构建查询的粗略方法。
You could query the original row, make changes to values that need changing and then update all the column values - regardless of what's actually changed. 您可以查询原始行,对需要更改的值进行更改,然后更新所有列的值-无论实际更改了什么。 This of course creates some unnecessary overhead but if execution time / processing power is not critical, then the overhead can be accepted.
当然,这会产生一些不必要的开销,但是如果执行时间/处理能力不是很关键,则可以接受这些开销。
it can be done using simple SQL query like below:- 可以使用如下所示的简单SQL查询来完成:
String query ="update table_name set col=something,col2=something where col3=?";
jdbcTemplate.update(query, yourParam);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.