zoukankan      html  css  js  c++  java
  • 2018夏季实训之有关数据库基本操作的函数

    添加

    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(),"添加数据成功,返回objectId为:"+objectId,Toast.LENGTH_SHORT).show();
    }else{
    Toast.makeText(getApplicationContext(),"创建数据失败:" + e.getMessage(),Toast.LENGTH_SHORT).show();
    }

    }
    });

    }
    });

    查询


    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 done(Person object, BmobException e) {
    if(e==null){
    Toast.makeText(getApplicationContext(),"查询成功",Toast.LENGTH_SHORT).show();
    String st=object.getName();
    TextView tv=findViewById(R.id.tv);
    tv.setText(st);

    }else{
    Toast.makeText(getApplicationContext(),"查询失败:" + e.getMessage(),Toast.LENGTH_SHORT).show();
    }

    }
    });
    }
    });


    依次查找

    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 {

    }
    }
    }
    });


    判断用户名密码是否正确

    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){ //可以先比较用户名,找到后再比对密码
    //成功登录,为person类,跳转。
    }

    }
    //显示用户名或密码错误。
    }
    }
    }
    });


    删除

    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(),"删除成功:"+p2.getUpdatedAt(),Toast.LENGTH_SHORT).show();
    }else{
    Toast.makeText(getApplicationContext(),"删除失败:" + e.getMessage(),Toast.LENGTH_SHORT).show();
    }
    }

    });

    }
    });
    }

    修改

    Person p2 = new Person();
    p2.setAddress("北京朝阳");
    p2.update("6b6c11c537", new UpdateListener() {

    @Override
    public void done(BmobException e) {
    if(e==null){
    toast("更新成功:"+p2.getUpdatedAt());
    }else{
    toast("更新失败:" + e.getMessage());
    }
    }

    });

  • 相关阅读:
    ax2009 在工作区中放置多个窗体
    领料过账 与 退料过账
    微软或将向诺基亚支付10亿美元推广研发诺基亚Windows Phone手机
    数据库设计的三个范式(整理硬盘时找到的,虽然很久但还很有用)
    把企业的软件和项目外包的好处
    项目开发项目管理(转)
    如何为 iPad 打造速度超快的 HTML5 软件
    Windows Phone7成为诺基亚核心目标
    Windows Phone7官方更新 增加复制粘贴
    Silverlight4 GDR3与Silverlight5 EAP1的变化
  • 原文地址:https://www.cnblogs.com/H-xiaofeng/p/9301839.html
Copyright © 2011-2022 走看看