Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared statement, execute batch, commit, rollback

 
Dimitrios Chatzidimitriou
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody!

Yes I know that this subject has been discussed before but I cannot find something helpful..


In a try block I have the following things..
I have prepared statements to INSERT data into a database. I put the statements in a batch.

Then I call executeBatch() and conn.commit.

In the catch block I call the rollback()..


The problem is that I do not know if the rollback works..



Is there anywhere a complete example showing how rollback works with prepared statements in a batch?


As you can understand I am really newbie and this is why I am not describing everything in a proper way..

Thanks for the effort!
 
Dimitrios Chatzidimitriou
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No matter how I try I cannot make it work..

Example code..




Can anyone tell me where rollback should be placed?


Thanks!
 
T Mishra
Ranch Hand
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that I do not know if the rollback works..

You can use debug statements or logger to track the inserted data.
or if you are using Eclipse IDE, you can mark a breakpoint within

You may use My SQL Workbench to check if all the rows were inserted in the database.
If you want to validate if the rollback occurs, you can insert invalid data.
Is there anywhere a complete example showing how rollback works with prepared statements in a batch?

Its not the combination of batch and rollback that matters here just know the individual concepts. You can find plenty of examples. example1 and example2 will get you started. Looks like execute batch is working fine, if you do not find debug statements in your console
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic