zoukankan      html  css  js  c++  java
  • 团队冲刺第九天

    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});
    //    }
    }
  • 相关阅读:
    VSFTPD匿名用户上传文件
    shell随机数比较
    Verse For Santa ---- CodeForces
    计算机基础--整数加减运算
    Hello,Blog!
    题解 P2486 【[SDOI2011]染色】
    题解 P1047 【校门外的树】
    题解 P1339 【[USACO09OCT]热浪Heat Wave】——线段树做法
    题解 P1197 【[JSOI2008]星球大战】
    题解 P1886 【滑动窗口】
  • 原文地址:https://www.cnblogs.com/dazhi151/p/12763678.html
Copyright © 2011-2022 走看看