wood burning stoves*
The moose likes Oracle/OAS and the fly likes ORA-02291: integrity constraint  error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "ORA-02291: integrity constraint  error" Watch "ORA-02291: integrity constraint  error" New topic
Author

ORA-02291: integrity constraint error

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

i am first fetching values from the table like following

here NOL is the variable in which i am fetching value from dropdown field
then i fetch the leave code in the variable nol like following

and if i am trying to print this code individually then it is giving right output but if i am trying insert this nol value in another table like following

then it is giving me following error

An Error Had occurred while accessing the database ORA-02291: integrity constraint (TRANS_R_LEAVE_FK1) violated - parent key not found

i don't understand why this is giving error as i am not inserting any value i am just fetching value
on following constraint it is giving me error

so the above constraint should give problem when i am trying to insert something .
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

If you aren't trying to insert anything, what is the "insert into TRANS(...)" statement for?
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Matthew Brown wrote:If you aren't trying to insert anything, what is the "insert into TRANS(...)" statement for?


no but i am inserting in the TRANS and the problem is coming in R_LEAVE which is showing that i am trying insert something in the R_LEAVE
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Megha Singhal wrote:no but i am inserting in the TRANS and the problem is coming in R_LEAVE which is showing that i am trying insert something in the R_LEAVE

No.

It is saying that the value you're trying to insert into the column LEV_TYPE in table TRANS is not one of these defined in table R_LEAVE.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Martin Vajsar wrote:
Megha Singhal wrote:no but i am inserting in the TRANS and the problem is coming in R_LEAVE which is showing that i am trying insert something in the R_LEAVE

No.

It is saying that the value you're trying to insert into the column LEV_TYPE in table TRANS is not one of these defined in table R_LEAVE.


LEAV_CODE and LEAV_DESC are both the fields in the R_LEAVE and fetching the values from the LEAV_CODE , i am inserting values in the LEV_TYPE as LEAV_CODE and LEV_TYPE is the same.
actualy what is happening in my form the user is inserting LEAV_DESC but as the field LEV_TYPE is numeric so i have to select LEAV_CODE corresponding LEAV_DESC from R_LEAVE then inserting in the TRANS table in the field LEV_TYPE.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Post more of your code then. The value for the LEV_TYPE column has got mangled somewhere on its way in.

You should learn to use PerparedStatement. You might start with a good tutorial. There are several reasons to do so, including security, performance and correctness of your code, as described here.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Martin Vajsar wrote:Post more of your code then. The value for the LEV_TYPE column has got mangled somewhere on its way in.

You should learn to use PerparedStatement. You might start with a good tutorial. There are several reasons to do so, including security, performance and correctness of your code, as described here.


what i have to post now all the queries i already posted and rest is the java code and that i can't post in this forum.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Well, if all was done as you have described it, then it would work. Since it doesn't, there is probably a bug somewhere in your code; if you cannot post the code (which I understand), we cannot help you spot the bug directly.

In this case, you can either debug your code using a debugger, or try to output values of key variables into a log so that you see what is happening to the variable which you're then inserting into the TRANS.LEV_TYPE column. You could even write the complete SQL statement you've constructed to a log (since you're not using PreparedStatement, but that is actually a bad thing too as I've already mentioned).
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Martin Vajsar wrote:Well, if all was done as you have described it, then it would work. Since it doesn't, there is probably a bug somewhere in your code; if you cannot post the code (which I understand), we cannot help you spot the bug directly.

In this case, you can either debug your code using a debugger, or try to output values of key variables into a log so that you see what is happening to the variable which you're then inserting into the TRANS.LEV_TYPE column. You could even write the complete SQL statement you've constructed to a log (since you're not using PreparedStatement, but that is actually a bad thing too as I've already mentioned).


ok then i try it to do through prepared statement, if then also my doesn't solve then i'll get back to you.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Switching to PreparedStatement alone probably won't resolve this error. It will just make your code protected from SQL injection attacks. It is possible, however, that while making changes needed to this you'll spot or incidentally fix the other bug.
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
Hi Megha,

What is the value of "nol" variable before insert statement? It can be null and not populated by your first query. As Martin said you should debug your code, it will reveal the error.
 
wood burning stoves
 
subject: ORA-02291: integrity constraint error
 
Similar Threads
problem while inserting values
how to remove whitespace before inserting
parent key not found
JDBC Connection
JDBC Connection