简体   繁体   中英

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

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 .

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:-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM