-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql2o can't rolback ? #342
Comments
Hey @mailtous , the e.g.
|
@mbraunerDE public void write() {
try (Connection connection = sql2o.beginTransaction()) {
Query q1 = connection.createQuery(" UPDATE `users` set name = 'alice' where id = 1");
q1.setAutoDeriveColumnNames(true);
q1.executeUpdate();
// DO SAVE
connection.commit();
// TEST DATA name is alice
Query q2 = connection.createQuery(" UPDATE `users` set name = 'dirk' where id = 1");
q2.executeUpdate();
// next row need add "connection.commit()", to real save "dirk" to DB
connection.commit();
// TEST DATA ROLLBACK, The "connection.rollback()" is executed, the name is alice, not dirk.
connection.rollback();
}
} ** TEST TWO: ** public void write() {
try (Connection connection = sql2o.beginTransaction()) {
Query q1 = connection.createQuery(" UPDATE `users` set name = 'alice' where id = 1");
q1.setAutoDeriveColumnNames(true);
q1.executeUpdate();
// DO SAVE
connection.commit();
// TEST DATA name is alice
Query q2 = connection.createQuery(" UPDATE `users` set name = 'dirk' where id = 1");
q2.executeUpdate();
// q2 is executed but not commit, so name of dirk is not save to DB.
}
} |
Hey, you added a second I recommend you this blog entry https://www.journaldev.com/23932/sql-commit-sql-rollback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The "connection.rollback()" has execute,But data still updated.
EG :
The text was updated successfully, but these errors were encountered: