Insert data and if already inserted then update in sql

后端 未结 7 3086
眼角桃花
眼角桃花 2021-02-20 13:18

I simply want to insert the data to a SQL database table and if there is some data inserted already then I want to update that data. How can I do this using Java. Kindly help me

7条回答
  •  死守一世寂寞
    2021-02-20 14:07

    try to following way:

    Example Query

    INSERT INTO table (id, name, city) VALUES(1, "ABC", "XYZ") ON DUPLICATE KEY UPDATE
    name="ABC", city="XYZ"

    for more help see documentation. Click here

提交回复
热议问题