Solved

Handling Transactions in java

Posted on 2007-03-20
6
1,057 Views
Last Modified: 2013-12-19
It is basically a application in struts. For a specific functionality, it navigates through 5 pages. It involves 4 database tables. in everypage, there are data inserts in the tables and also updates. The issue is, if there is some error in the final page, all the prior transactions should rollback, which is not happening.
I am carrying the same connection throughout this session. The inserts has to happen in the intermediate pages as based on the insert row, a id will be generated and that id is used in the other manipulations for the remaining pages. Pls suggest me how can i acheive a rollback if for any exceptions in the intermediate / final pages.
Pls respond ASAP, its urgent. Thanks
0
Comment
Question by:dreams4ever
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
elfe69 earned 125 total points
ID: 18755981
It is really not a good idea to keep a database transaction between several web pages because you will never know if the client leaves your pages and jump to any other site. In such a case, your transaction could stay pending for hours...
I think the best way to achieve such multi-pages insertion/update process is to store everything in temporary tables with the sessionID or any other ID and only when the last page is processed to move everything to the production tables
0
 

Author Comment

by:dreams4ever
ID: 18756957
Hi
Thanks for the suggestion and you are absolutely correct.  but unfortunately the project is in such a stage where it cannot go back for creating temp db tables etc. Is there any otherway other than that to solve this issue ?
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 125 total points
ID: 18757070
Yes, you should probably store the information in memory (maybe in Hashtables) of the web application (HttpSession object), and insert them in a bulk when ready. You will run into problems if you keep the connection open for long and if the user gets disconnected through a network time out or something of that sort.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18757079
Its not required to store it in temp DB tables - I think memory would do but yeah, you need to ensure it is cleaned in case of exceptions otherwise the memory usage will go high.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now