aspose file tools*
The moose likes JDBC and the fly likes java.sql.SQLException: ORA-02291 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: ORA-02291" Watch "java.sql.SQLException: ORA-02291" New topic
Author

java.sql.SQLException: ORA-02291

Richard Huges
Greenhorn

Joined: Nov 10, 2003
Posts: 6
I want to insert some Data into a table of an oracle db using a servlet.
Executing the insert-statement at the servlet, I receive the following exception. But there is no error when I start the insert-statment directly on the db.
java.sql.SQLException: ORA-02291: Versto� gegen Constraint (TIME.FK_LVB_ID). �bergeordn. Schl�ssel nicht gefunden
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:241)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1477)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:888)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2004)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1924)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2562)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:717)
at de.servlet.db.SQLGepl.set(SQLGeplanteLV.java:135)
at de.servlet.doPost(servlet.java:299)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:484)
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
The error message (java.sql.SQLException: ORA-02291) indicates a constraint violation where a parent key is not found. The constraint is "TIME.FK_LVB_ID", so that is where you should start looking. Your insert statement is violating that constraint. It should have nothing to do with whether the statement is being run in a JSP, in a Java app, or directly against the database.
You might also think about using the "executeUpdate()" method when doing a DELETE/UPDATE/INSERT rather than using "executeQuery()" Some drivers don't let you do updates when invoking "executeQuery()". In your case you should be OK since Oracle allows this, but it's good practice to use "executeQuery()" on when doing a "SELECT" and "executeUpdate()" in other cases.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: ORA-02291