insert data from one form into two diffent database table

Reply

Join Date: Jan 2007
Posts: 17
Reputation: jeet_portal is an unknown quantity at this point 
Solved Threads: 0
jeet_portal jeet_portal is offline Offline
Newbie Poster

insert data from one form into two diffent database table

 
0
  #1
Feb 27th, 2007
Hi Experts,

I have a small problem in my Projects. I need to insert the registration data into two differnt database table.I am using jsp code to do that opration. Pls Tell me some way in which i can ful fill this requirment.

Should i use two differnt connection,Resultset , Statement for each or any other way ...Pls suggest if any....

-Jeet
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: insert data from one form into two diffent database table

 
0
  #2
Feb 27th, 2007
you don't want to do that (at least not in JSP).
You want to use a servlet for that.
You also want to read a beginner's tutorial on JDBC.
You want to learn something about databases too.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: insert data from one form into two diffent database table

 
0
  #3
Apr 6th, 2007
Well, you can certainly do it by embedding some Java code in your JSP file...
Instead of trying to insert it directly from JSP tags...or a custom tag library...

You can create a custom tag library to handle this also... but it is basically handled by setting the DB Connection object to disable auot comit if insert and updates...

I use PostgreSQL 8.2 so I use conn.setAutoComit(false);
Then you insert the first and check if it worked... use conn.rollback(); if it failed and exit with and error code or message or whatever... if it worked insert the other part of the data to another table... chekc that it succeeded, and if not do the same as above...using conn.rollback(); that undoes both inserts if the second one fails... if the second succeeds then you can do conn.comit();
conn.setAutoComit(true);
and you're done...

many people set both, and check if they both suceed, then do the rollback or comit logic once.... BUT since DB transactions are more overhead than checking success... check after EACH and stop the transaction and roll it back upon the first failure...so you don't waste time with SQL inserts that will just get rolled back since an error already happened....

I set my auto comit back to true just completeness each time... but it doesn't really matter unless you are using static connections.... which you should be doing if you have a busy site...

Peace,
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC