File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint" Watch "java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint" New topic

java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 246

I got the problem when i try to insert the record in database using servlet the code is

Table names are Emp11 and foreign key value is DEPT_ID and its table has value 1,2,3,4 I hard coded it in the PreparedStatement
pstmt.setInt(7, 2);

//Exception is

java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (SCOTT.EMP11_DEPT1_FK1) violated - parent key not found

at oracle.jdbc.driver.SQLStateMapping.newSQLException(
at oracle.jdbc.driver.DatabaseError.newSQLException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.T4CTTIoer.processError(
at oracle.jdbc.driver.T4CTTIoer.processError(
at oracle.jdbc.driver.T4C8Oall.receive(
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at weblogic.servlet.internal.StubSecurityHelper$
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(
at weblogic.servlet.internal.ServletStubImpl.execute(
at weblogic.servlet.internal.ServletStubImpl.execute(
at weblogic.servlet.internal.WebAppServletContext$
at Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(
at weblogic.servlet.internal.WebAppServletContext.execute(

please help me
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

If you haven't already done so, I suggest doing an Intenet search for the Oracle error code you are getting, namely ORA-02291
Perhaps this link will help.

Good Luck,
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

I believe, the Department ID that you are supplying is not present in its master table anymore !

Not many get the right opportunity !
I agree. Here's the link:
subject: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint
jQuery in Action, 3rd edition