In order to insert data into a sqlite table named mytable in android I use query:
db.execSQL("INSERT INTO MYTABLE VALUES('','"+name+"',NOW());");
I want to check whether this query was successfully inserted into the table or not. In php (with mysql) you could easily do
if($result)
echo 'success';
else
echo 'not inserted';
But what is the equivalent code in android (with sqlite) to check whether the query has been successfully executed without any error?
According to the documentation execSQL throws an SQLException so I think your best bet is to surround your execSQL call with a try catch. You can then deal with whatever errors occurs in the catch. So something like this is what you want
try {
db.execSQL("INSERT INTO MYTABLE VALUES('','"+name+"',NOW());");
} catch (SQLException e) {
...deal with error
}
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