• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why my rollback doesn't work?

 
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone, I wrote a piece of code to test the rollback function.However, it doesn't work, can some one scanning through my code and tell me what the problem is .



Thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "it doesn't work" mean? What exactly happens if you run the code?
 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What does "it doesn't work" mean? What exactly happens if you run the code?



the entry"123456" and "root" have been inserted into the database which are not supposed to be inserted since the rollback was called!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which database are you using?
 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:Which database are you using?



I am using Mysql
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you change the Storage engine of your table to InnoDB
I think the default engine MyISAM doesnt support Transactions
Try it and let me know
 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arpit Panwar wrote:Make sure you change the Storage engine of your table to InnoDB
I think the default engine MyISAM doesnt support Transactions
Try it and let me know



Thanks Arpit, It works after change the engine from MyISAM to InnoDB.

Thanks for your help.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wei liu wrote:

Arpit Panwar wrote:Make sure you change the Storage engine of your table to InnoDB
I think the default engine MyISAM doesnt support Transactions
Try it and let me know



Thanks Arpit, It works after change the engine from MyISAM to InnoDB.

Thanks for your help.

Hi .. i too have the same problem. here in this case there is only one sql stmt... i have a set of updates and deletes .. and if i use the roolbak will it work?... thanks in advance

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, use the same connection object for all and commit after all are successful, rollback otherwise.

Jhakda
 
vidhya Narayanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u. I have another doubt o use the same connection for all the statements.. should i commit each after each stmt or i can commit at the end .
And can i use commit after the rollback?
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you said you have more than 1 sql, i presume you want to do an atomic transaction. We normally commit after successful completion of all transactions, roll back otherwise.

Jhakda
 
vidhya Narayanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jhakda Velu wrote:Since you said you have more than 1 sql, i presume you want to do an atomic transaction. We normally commit after successful completion of all transactions, roll back otherwise.

Jhakda

can i use rollback for DDL ... i think we cant... but wanted to know whether ther is any other method for doing it

 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vidhya Narayanan wrote:

Jhakda Velu wrote:Since you said you have more than 1 sql, i presume you want to do an atomic transaction. We normally commit after successful completion of all transactions, roll back otherwise.

Jhakda

can i use rollback for DDL ... i think we cant... but wanted to know whether ther is any other method for doing it



DDL is usually not transactional, so no.
 
Arpit Panwar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wei liu wrote:

Arpit Panwar wrote:Make sure you change the Storage engine of your table to InnoDB
I think the default engine MyISAM doesnt support Transactions
Try it and let me know



Thanks Arpit, It works after change the engine from MyISAM to InnoDB.

Thanks for your help.


Pleased to help
 
vidhya Narayanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:

vidhya Narayanan wrote:

Jhakda Velu wrote:Since you said you have more than 1 sql, i presume you want to do an atomic transaction. We normally commit after successful completion of all transactions, roll back otherwise.

Jhakda

can i use rollback for DDL ... i think we cant... but wanted to know whether ther is any other method for doing it



DDL is usually not transactional, so no.



I have a method to perform a rollback on the ddl statements. A method with all alter commands. This works fine if there is any error in the end of the actual code. If the actual code fails in-between the rollback method is called but the issue is there is an error while the alter stmts execute that were not created at all. Can anyone help me.
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic