在Spring MVC中解决dao.DuplicateKeyException
当我运行代码时,我得到了这个错误。我怎么解决呢?谢谢在Spring MVC中解决dao.DuplicateKeyException,spring,spring-mvc,jdbc,Spring,Spring Mvc,Jdbc,当我运行代码时,我得到了这个错误。我怎么解决呢?谢谢 StringBuffer contactQuery =new StringBuffer(); contactQuery.append("Insert into rescontact ("); contactQuery.append("ContactSeq,ResID,LastName,FirstName,ContactLabel,Phone1,Phone2)"); contactQuery.append("Values
StringBuffer contactQuery =new StringBuffer();
contactQuery.append("Insert into rescontact (");
contactQuery.append("ContactSeq,ResID,LastName,FirstName,ContactLabel,Phone1,Phone2)");
contactQuery.append("Values( ?,?,?,?,?,?,?)");
logClient.debug("Insert Query " + contactQuery.toString());
System.out.println(" Contact Insertion Query "+contactQuery.toString());
try{
JdbcTemplate jdbcTemplate = this.getJdbcTemplate();
return jdbcTemplate.update(contactQuery.toString(),new Object[] {contactSeq,resId,lastName,firstName,"WEB",Long.parseLong(contactresult),Long.parseLong(alternatecontactresult)});
例外情况:
回答者:看看S.Jay以前的帖子可能会有所帮助。回答者:看看S.Jay以前的帖子可能会有所帮助。
ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [Insert into rescontact (ContactSeq,ResID,LastName,FirstName,ContactLabel,Phone1,Phone2)Values( ?,?,?,?,?,?,?)]; ORA-00001: unique constraint (DOR_RESTINSP.SYS_C0011900) violated
09:31:59,851 ERROR [stderr] (http-localhost/127.0.0.1:8080-2) ; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (DOR_RESTINSP.SYS_C0011900) violated
09:31:59,852 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
09:31:59,852 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
09:31:59,852 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
09:31:59,852 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)
09:31:59,852 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
09:31:59,853 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970)
09:31:59,853 ERROR [stderr] (http-localhost/127.0.0.1:8080-2)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980)