SO I am writing a database manager for android, and in that class will be a method for writing to a table of that database..
SQLiteDatabase db = this.getReadableDatabase();
db.beginTransaction();
try {
//DO some db writing
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
my understanding is that this will automatically rollback the data should the transaction not be set to successful as it is in the try, but how do i catch if it was not successful so i can notify the user on success or rollback
just put the catch block before the finally block
SQLiteDatabase db = this.getReadableDatabase();
db.beginTransaction();
try {
//DO some db writing
db.setTransactionSuccessful();
}catch(Exception e){
// here you can catch all the exceptions
e.printStack();
} finally {
db.endTransaction();
}
examples for try catch
http://www.java-samples.com/showtutorial.php?tutorialid=293
http://tutorials.jenkov.com/java-exception-handling/basic-try-catch-finally.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With