Solved

Handling Transactions in java

Posted on 2007-03-20
6
1,059 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:Mayank S
Mayank S 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:Mayank S
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 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

27 Experts available now in Live!

Get 1:1 Help Now