• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ORA-02291: integrity constraint error

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you aren't trying to insert anything, what is the "insert into TRANS(...)" statement for?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic