Android--SQLite transaction

Source: Internet
Author: User

This is also achieved through Android Juint.

Based on the last project continued, the last project Portal: "Android–android juint and Sqlite" http://www.cnblogs.com/yydcdut/p/3790579.html

Update Database

 public   Personsqlite (context context) {super  (context, "person.db", null , 2        );  //  TODO auto-generated constructor stub  } @Override  public  void  ONUPGR Ade (Sqlitedatabase db, int  oldversion, int   NewVersion) { //  TODO Auto-generated method stub  System.out.println ("The database has changed!!        ");    Db.execsql ( ALTER TABLE person add account varchar () ); }

SQL processing Classes

 Public LongAddmoney (string name, string number,intMoney ) {Sqlitedatabase db=sqlite.getwritabledatabase (); //Db.execsql ("INSERT into person (name,number) VALUES (?,?)", New Object[]{name,number});Contentvalues values =Newcontentvalues (); Values.put ("Name", name); Values.put ("Number", number); Values.put ("Account", Money); Longid = db.insert ("Person",NULL, values);        Db.close (); returnID; }

Test

//Add Data First     Public voidTestaddmoney () {PersonDao2 DAO=NewPersonDao2 (GetContext ()); Dao.addmoney ("Wangwu", "123", 5000); Dao.addmoney ("Zhangsan", "321", 2000); }    //Transaction Processing     Public voidtesttransaction () {Personsqlite SQLite=NewPersonsqlite (GetContext ()); Sqlitedatabase DB=sqlite.getwritabledatabase ();        Db.begintransaction (); Db.execsql ("Update person set account=account-1000 where name =?",Newobject[]{"Zhangsan"}); Db.execsql ("Update person set account=account+1000 where name =?",Newobject[]{"Wangwu"});        Db.endtransaction ();    Db.close (); }

I'm the dividing line of the king of the Land Tiger.

Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01

Sqlite2.zip

Reprint Please specify source: Http://www.cnblogs.com/yydcdut

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.