0

I have an application in which I have to implement a function that concats old data in a column with the new data in the same column. The data is managed by DTO. At present the functionality deletes the old value and sets the new value by getter and setter methods. How can I change it so that I get the required functionality? Thanks in advance!

Lax_Sam
  • 1,099
  • 2
  • 14
  • 32

1 Answers1

0

Give a try with below query.

update t set data=concat(data, 'a');

For example current value is apple so after above query the new value will be applea

Refer : this

Alien
  • 15,141
  • 6
  • 37
  • 57
  • This is for concatenating two existing values in DB, if I am correct. What I need to do is to concat a new value returned from the client to the existing value in the same column in DB. Is there another way to do the same? – Lax_Sam Mar 13 '19 at 05:37
  • This is part of the functionality in need. I think my question was not clear. Each update corresponds to a single row. Different rows have different updates. So I should concatenate with different values for different rows. I should do that with spring MVC and I have been told not to write SQL query directly. Like to use json serialize and deserialize. Something of that kind! – Lax_Sam Mar 13 '19 at 05:46
  • 1
    if you dont want to go by query way then new StringBuilder().append("firstString").append("secondString").toString() and set it to the field. – Alien Mar 13 '19 at 05:49
  • Can I use json serialize and deserialize to do the same? If yes, can you tell me how to do it? I am new to Spring MVC and I am not yet clear on how to do it. – Lax_Sam Mar 13 '19 at 06:13
  • I have added another question with correct description of my problem. This is the link: https://stackoverflow.com/questions/55136529/serialize-and-deserialize-using-jackson-and-then-add-to-mysql-in-spring-mvc-appl – Lax_Sam Mar 13 '19 at 07:53