Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting data of two forms into two tables with same transaction id

 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have two forms and i am fetching the data from those two forms. i want to store the data of these two forms in two different
tables.

the problem is i want to maintain a common column taht is tranaaction_id , in both tables. also if i want this transaction_id to be generated dynamically i.e. my databse should generate it.


also both form data need to be inserted together. that is either both are inserted or none are inserted.

i am using MYSQL database.

can any one please suggest me the solution.

Thanks and regards.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a 3rd table for transaction_id with an auto_increment (in MySQL try "serial") column in as a primary key, then the other two tables can refer to this table as a foreign key??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need a transaction log table that stores these ids and has a relationship with both tables. Then if you wrap your insert into a transaction (making sure you are using one of the database engines that support transactions) you should get the behaviour you need.
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be a solution, let me know if I am going wrong

 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you add setAutocommit(true) to the catch??
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably yes, may be for the other transactions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic