其他分享
首页 > 其他分享> > 2月3日

2月3日

作者:互联网

体温上报,数据操作

 

体温录入

复制代码
public void insertDB(View view)
    {
        MyDBHelper mydbh=new MyDBHelper(this,"amydb.db",1);
        SQLiteDatabase sqldb=mydbh.getReadableDatabase();
        ContentValues contentvalues=new ContentValues();
        text1=(EditText)findViewById(R.id.tv_text1);
        text2=(EditText)findViewById(R.id.tv_text2);
        text3=(EditText)findViewById(R.id.tv_text3);
        text4=(EditText)findViewById(R.id.tv_text4);
        contentvalues.put("name",text1.getText().toString());
        contentvalues.put("dateandtime",text2.getText().toString());
        contentvalues.put("address",text4.getText().toString());
        contentvalues.put("wendu",text3.getText().toString());
        long flag=sqldb.insert("personwendu",null,contentvalues);
        Toast.makeText(this,"数据加入成功"+flag,Toast.LENGTH_LONG).show();
    }
复制代码

体温记录删除

复制代码
public void deleteDate(View view)
    {
        MyDBHelper mydbh=new MyDBHelper(this,"mydb.db",1);
        SQLiteDatabase sqldb=mydbh.getReadableDatabase();
        int flag=sqldb.delete("person","id=1",null);
        Toast.makeText(this,"已有"+flag+"条数据删除",Toast.LENGTH_LONG).show();
    }
复制代码

体温修改

复制代码
public void updateData(View view)
    {
        MyDBHelper mydbh=new MyDBHelper(this,"mydb.db",1);
        SQLiteDatabase sqldb=mydbh.getReadableDatabase();
        ContentValues contentvalues=new ContentValues();
        contentvalues.put("name","明明");
        contentvalues.put("age","12");
        int flag=sqldb.update("person",contentvalues,"name=?",new String[]{"李明"});
        Toast.makeText(this,"已有"+flag+"条数据修改",Toast.LENGTH_LONG).show();
    }
复制代码

历史记录查询

复制代码
 public void queryData(View view)
    {
        MyDBHelper mydbh=new MyDBHelper(this,"amydb.db",1);
        SQLiteDatabase sqldb=mydbh.getReadableDatabase();
        Cursor cursor=sqldb.rawQuery("select * from personwendu",null);
        String str="";
        if(cursor.moveToFirst())
        {
            do{
                String name=cursor.getString(cursor.getColumnIndex("name"));
                String dateandtime=cursor.getString(cursor.getColumnIndex("dateandtime"));
                String address=cursor.getString(cursor.getColumnIndex("address"));
                String wendu=cursor.getString(cursor.getColumnIndex("wendu"));
                str=str+name+"|"+dateandtime+"|"+wendu+"\n"+address+"\n";
            }while(cursor.moveToNext());
        }
        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setTitle("历史记录").setIcon(R.mipmap.ic_launcher).setMessage(str)
                .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        AlertDialog ad=builder.create();
        ad.show();
    }

标签:,mydbh,sqldb,cursor,MyDBHelper,contentvalues,new
来源: https://www.cnblogs.com/fujiaw/p/14911190.html