Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 122
  • 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.
 
Marshal
Posts: 69472
277
  • 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??
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.
 
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • 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
Marshal
Posts: 69472
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you add setAutocommit(true) to the catch??
 
Swastik Dey
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably yes, may be for the other transactions.
 
You got style baby! More than this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic