Android Development database, call Google internal API directive
Source: Internet
Author: User
<span id="Label3"></p><p><p>Invoking a database in this way is better than normal, concise and with a return value, to determine whether it is successful</p></p><p><p>Add</p></p><p><p>Sqlitedatabase Db=myopenhelper.getwritabledatabase ();<br>Contentvalues values=new contentvalues ();<br>Values.put ("username", "wangwu");<br>Values.put ("password", "110");<br>Long Insert=db.insert ("user", null, values);<br>Db.close ();<br>If (insert>0) {<br>Toast.maketext (getapplicationcontext (), "add success", 1). show ();<br>}else{<br>Toast.maketext (getapplicationcontext (), "add failed", 1). show ();<br>}</p></p><p><p>Delete</p></p><p><p>Sqlitedatabase Db=myopenhelper.getwritabledatabase ();<br>int Delete=db.delete ("user", "username=?", new string[]{"wangwu"});<br>Db.close ();<br>Toast.maketext (getapplicationcontext (), "deleted" +delete+ "line", 0). show ();</p></p><p><p></p></p><p><p>Update</p></p><p><p>Sqlitedatabase Db=myopenhelper.getwritabledatabase ();<br>Contentvalues values=new contentvalues ();<br>Values.put ("password", "123456789123");<br>int update=db.update ("user", values, "name=?", New string[]{"wangwu"});<br>Toast.maketext (getapplicationcontext (), "updated" +update+ "line", 0). show ();<br>Db.close ();</p></p><p><p>Find</p></p><p><p>Sqlitedatabase Db=myopenhelper.getwritabledatabase ();<br>Colums represents the column you want to query<br>Cursor cursor=db.query ("user", New string[]{"password"}, "username=?", new string[]{"wangwu"}, null, null, null);<br>If (cursor!=null&&cursor.getcount () >0) {<br>While (cursor.movetonext ()) {<br>String pwd=cursor.getstring (0);<br>System.out.println ("password:" +pwd);<br>}</p></p><p><p>1. Get the database</p></p><p><p>2. Working with the database</p></p><p><p>This column:</p></p><p><p>Contentvalues values=new contentvalues ();<br>Values.put ("password", "123456789123");<br>int update=db.update ("user", values, "name=?", New string[]{"wangwu"});</p></p><p><p>In this method, the form of the SQL statement has been written, missing some values</p></p><p><p>3. Complete the operation, close the database</p></p><p><p>Android Development database, call Google internal API directive</p></p></span>
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.