Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint

JC33Oct 27 2015 — edited Oct 27 2015

Hi,

We have a java program compiled by Java 1.8 and this program uses ojdbc7.jar.

The database is Oracle RAC 12.1.0.2.

Here is the code snippet.

conn.setAutoCommit(true);

pstmt = conn.prepareStatement("update mytable set datafield='xxxx' where keyfield='yyyy'");

int rows = pstmt.executeUpdate();

pstmt.close();

pstmt = null;

if(rows == 0) {

  pstmt = conn.prepareStatement("insert into mytable(keyfield, datafield) values('yyyy','xxxx')");

  pstmt.executeUpdate();  //<------- exception here

  pstmt.close();

  pstmt = null;

}

Sometimes we got the SQLIntegrityConstraintViolationException.

We couldn't figure out why this exception would happen.

Any advice would be greatly appreciated.

JC

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2015
Added on Oct 27 2015
3 comments
854 views