This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to insert into 2 tables at a time?

 
david hongw wang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDBC EDB Tomcat
--------------------------
when I built up the Database, I seperate a customer's information into 2 tables in 1 database.

when I get customer's information from a html form, I try to insert these information into 2 tables at the same time, the 2 tables have a cust_id as the same coloum,
-----------------------
the question is:
how can I control when inserting the data, if one of the sql failed, the other successed one could roll back?
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by david hongw wang:
JDBC EDB Tomcat
--------------------------
when I built up the Database, I seperate a customer's information into 2 tables in 1 database.

when I get customer's information from a html form, I try to insert these information into 2 tables at the same time, the 2 tables have a cust_id as the same coloum,
-----------------------
the question is:
how can I control when inserting the data, if one of the sql failed, the other successed one could roll back?


Using a database that properly supports transactions (many but not all):



If your database doesn't support transactions, then it's real real hard and I don't want to hurt my brain tonight trying to remember how to do that. In fact, there are enough free and cheap databases that do support transactions correctly that there's no point in wasting good brain cells on the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic