java - Optimize / Improve my SQL update -



java - Optimize / Improve my SQL update -

okay, allow me state first. new sql , don't know lot it. started using , i've been trying larn , improve. please explain state, may not understand mutual terms etc.

the sql code wrote works intend to, string seems obnoxious , made me think can't quite right.

insert reputations(uuid, warn, bandate, reasons, mods) values ('{0}', '{1}', '{2}', concat(reasons, '{3}'), concat(mods, '{4}')) on duplicate key update warn = '{1}', bandate = '{2}', reasons=concat(reasons, '{3}'), mods=concat(mods, '{4}')

in java code looks this:

as can see, have no clue on how format/indent utilize this. tips appreciated.

i should explain {n}'s spaces replace info want. example, replace {0} uuid.

so, question is. there improve way this? tips or help appreciated. cheers!

i don't understand part:

values ('{0}', '{1}', '{2}', concat(reasons, '{3}'), concat(mods, '{4}')) ------------------------------------^

the utilize of column name there should generating error.

perhaps statement want:

insert reputations(uuid, warn, bandate, reasons, mods) values ('{0}', '{1}', '{2}', '{3}', '{4}') on duplicate key update warn = values(warn), bandate = values(bandate), reasons = concat(reasons, values(reasons)), mods = concat(mods, values(mods));

in on duplicate key part, can utilize values() new value particular column. in addition, suspect might want have separator lastly 2 concatenations:

reasons = concat_ws('; ', reasons, values(reasons)), mods = concat_ws('; ', mods, values(mods));

the utilize of concat_ws() has nice side effect if values ever null -- still leave remaining values.

java mysql sql optimization

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -