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});
    //    }
    }
  • 相关阅读:
    mysql 覆盖索引
    mysql 连接查询 和 子查询
    mysql varchar
    uchome 是如何将数据插入数据库的
    Tomcat5 在windows安装服务
    Linux中错误码及描述查看
    Longines浪琴手表型号解释
    perl 安装 Net::Telnet 模块
    php一些错误的显示问题
    firefox样式表cursor和兼容Ie firefox,解决文字溢出的问题(wordwrap:breakword;wordbreak:breakall)
  • 原文地址:https://www.cnblogs.com/dazhi151/p/12763678.html
Copyright © 2011-2022 走看看