When Android was developed, SQLite created the table successfully, insert does not error, but there is no data to insert the reason

Source: Internet
Author: User
Tags sqlite create table

In the Android development process, often to use SQLite to store some data, this application should be more common, but sometimes unavoidably inadvertently, will appear sqlite create table success, insert not error, but no data inserted.

For specific questions, see the following code:

Context CTX;
Sqlitedatabase db = Dbopenhelper.getwritabledatabase ();

Open transaction
Db.begintransaction ();
try{
Database operations
For (...) {
Inserting data
Db.insert (table, values);
}

//SET transaction flag to be successful, commit transaction when end transaction
//(Be sure to add this sentence, otherwise the insert succeeds, but the database has no data)
db.settransactionsuccessful ();   
}
catch (Exception ex) {

} finally {
//End Transaction method checks whether a transaction's flag is successful,
//If the program executes this method before calling the Settransactionsuccessful () method to set the transaction flag to successful then commit the transaction
//If the Settransactionsuccessful () method is not called, the transaction is rolled back.
db.endtransaction ();
}

When Android was developed, SQLite created the table successfully, insert does not error, but there is no reason for data insertion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.