aspose file tools*
The moose likes JDBC and the fly likes Issues in db insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Issues in db insertion" Watch "Issues in db insertion" New topic
Author

Issues in db insertion

shweta misra
Greenhorn

Joined: Jun 06, 2012
Posts: 10
Hi,

We are facing a problem in our java application while inserting and updating data into the db.
The code for insertion/updation has been written in core java (jdk1.6).

The steps are as follows :-
1) code is written to insert/update data is 3 tables in the db
2) Soon after step 1, an exception is thrown

a snippet of the code is given below :-

dbentry.finalDBEntriesForSessionRelease(sessionId,"UPDATE", customCdrSession, "error_closed"); //update the db

throw ExceptionType.SERVICE_ERROR.createEx(); //throw exception.

We observed that the java code runs perfectly , the exception is also thrown as expected. The logs show that the db
insertion/updation is done . there are no errors.
But the problem is that the db insertion done in the 3 tables is not visible when we actually go and look into the tables. i.e
we are not able to see the new row that is inserted and the changed rows that are updated in the tables. its like as if nothing
happened. There are no errors also... code works perfectly.

Another observation is that the moment we remove the "throw Exception..." line, we are able to see the db changes in the tables.

Does anyone know why this is happening and how to resolve this ??

Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3455
    
  47

Welcome to the Ranch, Shweta!

My really, really wild guess is that you have turned autocommit off and there is a rollback somewhere in your exception handling code.

If this is true, the resolution depends on what you're tying to achieve. Rolling back changes when an error occurs is quite common and reasonable approach, actually.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

sorry, thre is not enough information here to work upon.

Please read this link and come back to us. isolate the problem

shweta misra
Greenhorn

Joined: Jun 06, 2012
Posts: 10
thanks Martin !

our application is deployed in the Weblogic application server and the transactions are container managed and the EJBs are stateless session beans. I found that for container managed transactions, in case of a system exception the transaction is rolled back . this will include db updates also.

as per our business logic we need to update certain db tables before we throw the exception but looks like its not possible.

Can you suggest any workaround ?
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

are these inserts to record error details?

Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
shweta misra wrote:thanks Martin !

our application is deployed in the Weblogic application server and the transactions are container managed and the EJBs are stateless session beans. I found that for container managed transactions, in case of a system exception the transaction is rolled back . this will include db updates also.

as per our business logic we need to update certain db tables before we throw the exception but looks like its not possible.

Can you suggest any workaround ?


I was wondering why you are throwing an Exception on purpose - and wondering too if that is what Wendy is getting at. But if you have autocommit turned off, you could force the commit before throwing the exception.


~Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issues in db insertion
 
Similar Threads
"Handle or Declare" Rule for Checked Exceptions
Batch Processing of Queries with PreparedStatement
Should Bean developer throw RemoteException & related stuff
URLyBird: Data Validation in database code
How to fetch Date Field from excel sheet in Java