2018 Summer training functions for basic database operations

Source: Internet
Author: User
Tags getmessage gettext

Add to

Final person p2 = new person ();

Button Bt=findviewbyid (R.ID.BT);

Bt.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String string= ((EditText) Findviewbyid (R.id.et1)). GetText (). toString ();
P2.setname (string);
P2.save (New savelistener<string> () {
@Override
public void-Done (String objectId, bmobexception e) {

if (e==null) {
Toast.maketext (Getapplicationcontext (), "Add data successfully, return ObjectId as:" +objectid,toast.length_short). Show ();
}else{
Toast.maketext (Getapplicationcontext (), "Failed to create data:" + e.getmessage (), Toast.length_short). Show ();
}

}
});

}
});

Inquire


Button Bt2=findviewbyid (R.ID.BT2);
Bt2.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String string1= ((EditText) Findviewbyid (R.id.et2)). GetText (). toString ();
bmobquery<person> bmobquery = new bmobquery<person> ();
Bmobquery.getobject (string1, new querylistener<person> () {
@Override
public void do (Person object, bmobexception e) {
if (e==null) {
Toast.maketext (Getapplicationcontext (), "Query succeeded", Toast.length_short). Show ();
String St=object.getname ();
TextView Tv=findviewbyid (r.id.tv);
Tv.settext (ST);

}else{
Toast.maketext (Getapplicationcontext (), "Query failed:" + e.getmessage (), Toast.length_short). Show ();
}

}
});
}
});


Search in turn

String sql = "Select *from myaddbook";
New Bmobquery<person> (). Dosqlquery (SQL, new sqlquerylistener<person> () {
@Override
public void-Done (bmobqueryresult<person> Bmobqueryresult, bmobexception e) {
if (E = = null) {
list<person> list = (list<person>) bmobqueryresult.getresults ();
if (list = null && list.size () > 0) {
for (int i = 0; i < list.size (); i++) {
Person book = List.get (i);

}
} else {

}
}
}
});


Determine if the user name password is correct

Final String username= "";
Final String password= "";
String sql = "Select *from person";
New Bmobquery<person> (). Dosqlquery (SQL, new sqlquerylistener<person> () {
@Override
public void-Done (bmobqueryresult<person> Bmobqueryresult, bmobexception e) {
if (E = = null) {
list<person> list = (list<person>) bmobqueryresult.getresults ();
if (list = null && list.size () > 0) {
for (int i = 0; i < list.size (); i++) {
Person person = list.get (i);
if (Person.getusername () ==username&&person.getpassword () ==password) {//You can compare the user name first, find and then then compare the password
Successful login, for the person class, jump.
}

}
The user name or password error is displayed.
}
}
}
});


Delete

Button Bt3=findviewbyid (R.ID.BT3);
Bt3.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String string2= ((EditText) Findviewbyid (R.id.et3)). GetText (). toString ();
P2.setobjectid (string2);
P2.delete (New Updatelistener () {

@Override
public void-Done (bmobexception e) {
if (e==null) {
Toast.maketext (Getapplicationcontext (), "Delete succeeded:" +p2.getupdatedat (), Toast.length_short). Show ();
}else{
Toast.maketext (Getapplicationcontext (), "Delete failed:" + e.getmessage (), Toast.length_short). Show ();
}
}

});

}
});
}

Modify

person P2 = new person ();
P2.setaddress ("Chaoyang, Beijing");
P2.update ("6b6c11c537", new Updatelistener () {

@Override
public void-Done (bmobexception e) {
if (e==null) {
Toast ("Update succeeded:" +p2.getupdatedat ());
}else{
Toast ("Update failed:" + e.getmessage ());
}
}

});

2018 Summer training functions for basic database operations

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.