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

Recommended Answers

All 2 Replies

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.

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,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.