团队冲刺第九天

1、今天自己做的是建立了数据库。准备将产生的数据存放到数据库之中。

主要的数据库代码人如下:

package com.example.dingwei2.DBOpenMessageUser;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.example.dingwei2.bean.location;

public class DBOpenMessageUserlocation extends SQLiteOpenHelper
{
    final String db_location="create table db_location (_id integer primary key autoincrement,username varchar,date varchar,points varchar,distance integer,time varchar,energy integer,speed integer)";
    public DBOpenMessageUserlocation(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, null, version);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(db_location);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i("数据","更新"+"oldVerSion"+"-->"+newVersion);
    }

    /**
    *数据库的相关操作
    * **/
    //增加信息
    public void insertlocation(SQLiteDatabase sqLiteDatabase, location location) {
        ContentValues cv = new ContentValues();
        cv.put("username", location.username);
        cv.put("date", location.date);
        cv.put("points", location.points);
        cv.put("time", location.time);
        cv.put("distance", location.distance);
        cv.put("energy", location.energy);
        cv.put("speed", location.speed);
        sqLiteDatabase.insert(db_location, null, cv);
    }
//删除信息
    public void deletebyid(Integer id)
    {
        SQLiteDatabase database = getWritableDatabase();
        database.execSQL("delete from db_location where id=?", new String[]{String.valueOf(id)});
    }
    //查找
       // database.execSQL("delete from db_location where  date=? and username=?", new String[]{date,username});

    public Cursor getAllLocation(String username) {
        SQLiteDatabase database = getWritableDatabase();
        return database.query("db_wen", null, "username=?",new String[]{username},null, null,"distance desc" );//"userdata desc"
    }


//    public void updatauser(String username,String usercheck)
//    {
//        SQLiteDatabase database = getWritableDatabase();
//        ContentValues values=new ContentValues();
//        values.put("usercheck",usercheck);
//        database.update("db_wen",values,"username=?",new String[]{username});
//    }
//    public void updatauserpicture(String username,String userpicture)
//    {
//        SQLiteDatabase database = getWritableDatabase();
//        ContentValues values=new ContentValues();
//        values.put("userpicture",userpicture);
//        database.update("db_wen",values,"username=?",new String[]{username});
//    }
//    public void updatapassword(String username,String password)
//    {
//        SQLiteDatabase database = getWritableDatabase();
//        ContentValues values=new ContentValues();
//        values.put("password",password);
//        database.update("db_wen",values,"username=?",new String[]{username});
//    }
}

 

posted @ 2020-04-23 21:30  喜欢爬的孩子  阅读(125)  评论(0编辑  收藏  举报