Java 使用SpringJDBC更新查询

Java 使用SpringJDBC更新查询,java,sql,spring,jdbc,spring-jdbc,Java,Sql,Spring,Jdbc,Spring Jdbc,我正在尝试构建一个更新查询-例如 update table A set Column 1 = ,Column 2= , Column 3..... where Constant selection criteria Condition 1 - update only Column 1 Condition 2 - update Column 1 and Column 2 and so on. ( 6 combinations in this case) 假设要更新的最大列数为3,并且可以有任

我正在尝试构建一个更新查询-例如

update table A set Column 1 = ,Column 2= , Column 3..... where 
Constant selection criteria
Condition 1 - update only Column 1
Condition 2 - update Column 1 and Column 2 and so on. ( 6 combinations in this case)
假设要更新的最大列数为3,并且可以有任何组合,这取决于某些业务规则,例如

update table A set Column 1 = ,Column 2= , Column 3..... where 
Constant selection criteria
Condition 1 - update only Column 1
Condition 2 - update Column 1 and Column 2 and so on. ( 6 combinations in this case)
在这种情况下,如何构建更新查询

我没有使用Hibernate


我可以想出一种只构建查询的粗略方法。

您可以查询原始行,对需要更改的值进行更改,然后更新所有列值,而不管实际更改了什么。这当然会产生一些不必要的开销,但如果执行时间/处理能力不重要,则可以接受该开销。

可以使用以下简单的SQL查询完成:-

String query ="update table_name set col=something,col2=something where col3=?";
jdbcTemplate.update(query, yourParam);

更新时,您是否有原始行可供使用?@heikkim我会这样做的。我想到了这一点。让我们看看是否有人可以提供其他方法