Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Question Unanswered: PreparedStatement not working from an EJB...


    I need to communicate with database from a stateless session EJB. We are using simple JDBC (just like from any normal class) and not the EJBServer connection pools.

    Table A has a primary key and table B references it for a foreign key.
    Now, I am inserting a record in table A and in the same method, inserting a corresponding record in table B.

    I am using PreparedStatement for the second insert (table B) and am getting the 'foreign key constraint violated' error, even though the required primary key value is now present in table A.

    Interestingly, if I use Statement now, and change nothing else, it works!

    I would be grateful if someone could throw any light on this.

    Note: Statement and PreparedStatement both are working from simple java class.

  2. #2
    Join Date
    Mar 2002
    Reading, UK
    Is it inserting in the wrong order i.e. into table B first then table A (why this behaviour would change using preparedStatement I dont know : ( ). If it is try using deferred constraints where the constraint is checked at commit time not at insert time (but you may need to change your error handling logic to cope with errors at commit time as opposed to insert time).


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts