aspose file tools*
The moose likes JDBC and the fly likes Is there a way of knowing which record failed in Batch Insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Is there a way of knowing which record failed in Batch Insert" Watch "Is there a way of knowing which record failed in Batch Insert" New topic
Author

Is there a way of knowing which record failed in Batch Insert

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Dear All

Inside a loop I am setting the input parameters of prepared statement to be inserted ane suppose it fails due to a rason that input value is too large for a colmn for some record in an iteration i.
Since i already has reached the threshold value when I am executing a batch so I seem to have lost which culprit record at which iteration caused it
PreparedStatement doesn't seem to have any clue on finding this
Does any one of you have faced similar situation and know of any crack ?

Thanks in advance


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
It might help if you can give code snippet. It's not clear what you were doing with the description. Anyway
- Is the loop used to construct the statement and added to a batch to be executed through executeBatch()? If not what do you meant by crossed the threshold?
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
I am sort of confused... a crack for what? A crack is a program or process that makes crippled software into fully functioning software, so I don't see how that pertains to your situation.(At least that's what I always thought it meant).

You could do several different things. One, you could check the data for size before it gets inserted into the prepared statement. Or you could dump your data into a comma delimited file and insert the data from the sql command line.
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
I am using executeBatch and by threshold I meant the size of collection (which I am passing ott his function)
I get the input paremeters from the dataObject of this collection and set them as setters of preparedstatement which I have created before loop

Code snippet is very huge but this is what I am doing (In a nutshell)
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
If you look at the executeBatch() api description, the return type is int array with the status code of the each statement executed (the order in which it's added to the batch). It should be fairly easy to identify the statement that failed (unless the driver you use doesn't support this feature).

Take a look at the executeBatch() api description let us know if it doesn't work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a way of knowing which record failed in Batch Insert
 
Similar Threads
How Multimap Records of 1'st table to 2'nd one?
BatchUpdateException .UpdateCounts
running java app as a batch job
Why I lost points in locking, pls comment on my code
Html Textarea queries