I use tomcat for my server side with Mysql Server 5.5.
i use Spring framework for the database connectivity.
I would like to be able to insert a row to a table using simpleJdbcInsert. if the insert fails because of a duplicate i want it to replace the duplicated row.
is there a way to do that simpleJdbcInsert or should I just use jdbcTemplate and create my on query with “ON DUPLICATE” statement?
thanks
logically, duplication occurs when there is a double primary key.
so, if you are using the traditional JDBC or even Hibernate, then you should check if the same primary key value already exists, before you insert the new one.
but if the primary key is not set yet, or will be set by the DBMS, there will be different problem.
in JDBC, again you need to do the old style manual checking by querying before inserting the new one, but
in Hibernate, you just need to update it. Hibernate will create the new if there is no duplicate, but will replace if there is a duplicate,.