944,004 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 8315
  • JSP RSS
Feb 27th, 2007
0

insert data from one form into two diffent database table

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeet_portal is offline Offline
18 posts
since Jan 2007
Feb 27th, 2007
0

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

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 6th, 2007
0

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

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,
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Help Needed in Struts-jsp
Next Thread in JSP Forum Timeline: Combobox Woes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC