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());
    }
    }

    });

  • 相关阅读:
    手把手教你利用create-nuxt-app脚手架创建NuxtJS应用
    初识NuxtJS
    webpack打包Vue应用程序流程
    用选择器代替表格列的筛选功能
    Element-UI
    Spectral Bounds for Sparse PCA: Exact and Greedy Algorithms[贪婪算法选特征]
    Sparse Principal Component Analysis via Rotation and Truncation
    Generalized Power Method for Sparse Principal Component Analysis
    Sparse Principal Component Analysis via Regularized Low Rank Matrix Approximation(Adjusted Variance)
    Truncated Power Method for Sparse Eigenvalue Problems
  • 原文地址:https://www.cnblogs.com/H-xiaofeng/p/9301839.html
Copyright © 2011-2022 走看看