| | |
insert data from one form into two diffent database table
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2007
Posts: 17
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2007
Posts: 83
Reputation:
Solved Threads: 2
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,
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,
![]() |
Similar Threads
- How to insert data into database? (JSP)
- a blank form to insert data???? (Visual Basic 4 / 5 / 6)
- how to insert data from dataset into database (VB.NET)
- Insert Data in to Db from the Dynamic Rows (HTML and CSS)
- Unable to insert data into database. (MySQL)
- Unable to insert data into SQL Database (ASP)
- database table design problems (Database Design)
Other Threads in the JSP Forum
- Previous Thread: Help Needed in Struts-jsp
- Next Thread: Combobox Woes
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






