首页 > 其他分享 >每日总结-23.3.21

每日总结-23.3.21

时间:2023-03-21 20:55:54浏览次数:37  
标签:总结 cur yonghuming con String 23.3 new null 21

关于Android studio操作SQLite的方法

package com.example.daka1;

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

import java.util.ArrayList;
import java.util.List;

/**
 * 数据库访问对象
 * DAO:DATEBASE ACCESS OBJECT
 * 是控制层于数据库交互的中间层,用于做数据库的增删改查具体实现
 * */
public class Thesql {
    //SQLiteDatabase对象封装了所有SQLite的增删改查语句的操作方法,让开发者直接调用就行
    private SQLiteDatabase db;

    public Thesql(Context context){
        //初始化刚刚写的MySQLiteHelper对象
        MySQLiteHelper mySQLiteHelper = new MySQLiteHelper(context);

        //获取sqLiteDatabase对象
        db = mySQLiteHelper.getWritableDatabase();
    }

    public boolean adduser(String xuehao,String yonghuming,String shoujihaoma,String banji,String mima)
    {
        ContentValues con = new ContentValues();
        con.put("xuehao",xuehao);
        con.put("yonghuming",yonghuming);
        con.put("shoujihaoma",shoujihaoma);
        con.put("banji",banji);
        con.put("mima",mima);
        con.put("zuichang",0);
        long i = db.insert("user",null,con);
        return i>0?true:false;
    }

    public boolean xiugai(String xuehao,String yonghuming,String shoujihaoma,String banji,String mima)
    {
        ContentValues con = new ContentValues();
        con.put("xuehao",xuehao);
        con.put("yonghuming",yonghuming);
        con.put("shoujihaoma",shoujihaoma);
        con.put("banji",banji);
        con.put("mima",mima);
        long i = db.update("user",con,"yonghuming=?",new String[]{yonghuming});
        return i>0?true:false;
    }
    public boolean xiugai(String yonghuming,Userpd userpd)
    {
        ContentValues con = new ContentValues();
        con.put("xuehao",userpd.xuehao);
        con.put("yonghuming",userpd.yonghuming);
        con.put("shoujihaoma",userpd.shoujihaoma);
        con.put("banji",userpd.banji);
        con.put("mima",userpd.mima);
        con.put("zuichang",userpd.zuichang);
        long i = db.update("user",con,"yonghuming=?",new String[]{yonghuming});
        return i>0?true:false;
    }
    public Userpd chaxun(String yonghuming)
    {
        Cursor cur=db.query("user",null,"yonghuming=?",new String[]{yonghuming},null,null,null);
        if(cur.getCount()==1)
        {
            cur.moveToFirst();
            int id= cur.getInt(0);
            String xuehao=cur.getString(1);
            //String yonghuming1=cur.getString(2);
            String shoujihaoma=cur.getString(3);
            String banji=cur.getString(4);
            String mima=cur.getString(5);
            int zuichang= cur.getInt(6);
            Userpd user1 = new Userpd();
            user1.id=id;
            user1.xuehao=xuehao;
            user1.yonghuming=yonghuming;
            user1.shoujihaoma=shoujihaoma;
            user1.banji=banji;
            user1.mima=mima;
            user1.zuichang=zuichang;
            return user1;
        }
        else return null;
    }
    public Userpd[] chaxunalluser()
    {
        Cursor cur=db.query("user",null,null,null,null,null,null);
        int n = cur.getCount();
        Userpd[] userpds = new Userpd[n];
        for(int i=0;i<n;i++)
        {
            userpds[i]=new Userpd();
        }
        int i=0;
        while(cur.moveToNext())
        {
            userpds[i].xuehao=cur.getString(1);
            userpds[i].yonghuming=cur.getString(2);
            userpds[i].banji=cur.getString(4);
            i++;
        }
        return userpds;
    }

    public boolean ispass (String yonghuming,String password)
    {
        Userpd pd = chaxun(yonghuming);
        if(pd!=null)
        {
            if(pd.mima.equals(password))
                return true;
            else
                return false;
        }
        else
            return false;
    }

    public boolean adddakajilu(String riqi,String guanjianzi,String meirizongjie,String user)
    {
        ContentValues con = new ContentValues();
        con.put("riqi",riqi);
        con.put("guanjianzi",guanjianzi);
        con.put("meirizongjie",meirizongjie);
        con.put("user",user);
        long i = db.insert("dakajilu",null,con);
        return i>0?true:false;
    }
    public Dakapd dakachaxun(String riqi)
    {
        Cursor cur=db.query("dakajilu",null,"riqi=?",new String[]{riqi},null,null,null);
        if(cur.getCount()==1)
        {
            cur.moveToFirst();
            int id= cur.getInt(0);
            //String riqi1=cur.getString(1);
            String guanjianzi1=cur.getString(2);
            String meirizongjie1=cur.getString(3);
            String user1=cur.getString(4);
            Dakapd dakapd = new Dakapd();
            dakapd.id=id;
            //dakapd.riqi=riqi1;
            dakapd.guanjianzi=guanjianzi1;
            dakapd.meirizongjie=meirizongjie1;
            dakapd.user=user1;
            return dakapd;
        }
        else return null;
    }
    public Dakapd dakachaxun(String riqi,String user)
    {
        Cursor cur=db.query("dakajilu",null,"riqi=? and user=?",new String[]{riqi,user},null,null,null);
        if(cur.getCount()==1)
        {
            cur.moveToFirst();
            int id= cur.getInt(0);
            //String riqi1=cur.getString(1);
            String guanjianzi1=cur.getString(2);
            String meirizongjie1=cur.getString(3);
            String user1=cur.getString(4);
            Dakapd dakapd = new Dakapd();
            dakapd.id=id;
            //dakapd.riqi=riqi1;
            dakapd.guanjianzi=guanjianzi1;
            dakapd.meirizongjie=meirizongjie1;
            dakapd.user=user1;
            return dakapd;
        }
        else return null;
    }
    public Dakapd[] dakachaxunyonghu(String user)
    {
        Cursor cur=db.query("dakajilu",null,"user=?",new String[]{user},null,null,null);
        if(cur.getCount()!=0&&cur.getCount()!=-1)
        {
            int n=Getuserdakacishu(user);
            Dakapd[] dakapd =new Dakapd[n];
            for(int i=0;i<n;i++)
            {
                Dakapd dakapd1=new Dakapd();
                dakapd[i]=dakapd1;
            }
            int i=0;
            while(cur.moveToNext())
            {
                dakapd[i].riqi=cur.getString(1);
                dakapd[i].guanjianzi=cur.getString(2);
                dakapd[i].meirizongjie=cur.getString(3);
                dakapd[i].user=cur.getString(4);
                i++;
            }
            return dakapd;
        }
        else return null;
    }
    public Dakapd[] dakachaxunGAndM(String guanjianzi,String meirizongjie)
    {
        Cursor cur=db.query("dakajilu",null,"guanjianzi like ? and meirizongjie like ? ",new String[]{"%"+guanjianzi+"%","%"+meirizongjie+"%"},null,null,null);
        if(cur.getCount()!=0&&cur.getCount()!=-1)
        {
            int n=cur.getCount();
            Dakapd[] dakapd =new Dakapd[n];
            for(int i=0;i<n;i++)
            {
                Dakapd dakapd1=new Dakapd();
                dakapd[i]=dakapd1;
            }
            int i=0;
            while(cur.moveToNext())
            {
                dakapd[i].riqi=cur.getString(1);
                dakapd[i].guanjianzi=cur.getString(2);
                dakapd[i].meirizongjie=cur.getString(3);
                dakapd[i].user=cur.getString(4);
                i++;
            }
            return dakapd;
        }
        else return null;
    }
    public String[] Getalluser ()
    {
        String[] strings=new String[120];
        int i=0;
        Cursor cur=db.query(true,"dakajilu",new String[]{"id","user"},null,null,"user",null,null,null,null);
        while(cur.moveToNext())
        {
            String user1=cur.getString(1);
            strings[i]=user1;
            i++;
        }
        return strings;
    }
    public int Getuserdakacishu (String user)
    {
        Cursor cur=db.query("dakajilu",null,"user=?",new String[]{user},null,null,null);
        return cur.getCount();
    }





    public List<Userpd> query()
    {
        List<Userpd> list = new ArrayList<>();
        Cursor cur = db.query("user",null,null,null,null,null,null,null);
        if(cur!=null)
        {
            while(cur.moveToNext())
            {
                Userpd user =new Userpd();
                String id = String.valueOf(cur.getInt(0));
                list.add(user);
            }
            cur.close();
            return list;
        }
        else return null;
    }



}

 

标签:总结,cur,yonghuming,con,String,23.3,new,null,21
From: https://www.cnblogs.com/laobing6214/p/17241386.html

相关文章

  • 3.21每日总结
    packagecom;importjava.sql.*;publicclassDB{publicConnectionconn=null;publicStatementstmt=null;publicResultSetrs=null;S......
  • 3.21总结
    一、新建Newproject空项目存放地址CodeFile一个moduleJavasrc创建包package——com.zihan.hello包内创建类class二、注释 1.//注释单行;/**/注释多行;/***/......
  • COMP3221 Routing Algorithm
    Due:March31st,2023(Friday,Week6)by11:59PMCOMP3221Assignment1:RoutingAlgorithmThegoalofthisassignmentistoimplementroutingprotocolsforane......
  • 闲话 23.3.21
    闲话【碎片】0.8/1明天集训就结束了(同学们吃外卖吃够了吗(模拟赛T1会维护静态区间子区间mex和吧?不会?会维护静态区间mex吧?套个历史版本和就没了。mex是最小,mix......
  • 2023年3月21日
    计划写中期报告,写完最好看业务功能的实现执行09点32分 填写了考勤记录搞清楚接口调试是怎么回事,怎么弄的,然后写需求分析,画用例图,管理员登陆不上,不知道密码......
  • 常见trick总结
    记录一些做题时遇到的有价值的trick。CF1717E\[a+b=n\]\[\gcd(a,b)=\gcd(a,a+b)=\gcd(a,n)=\varphi(n)\]P2619二分\(\Delta\),每条白边加上\(\Delta\)求\(\te......
  • 20230321
    Shell运算符表达式和运算符之间要有空格,例如2+2是不对的,必须写成2+2,这与我们熟悉的大多数编程语言不一样。完整的表达式要被``包含算术运算符与C语言的没有区别......
  • 3.21 黑马提高
    构造函数调用规则默认情况下,C++编译器至少给类添加3个函数1、默认构造函数(无参,函数体为空);2、默认析构函数(无参,函数体为空);3、默认拷贝构造函数,对属性进行值拷贝。1、......
  • 今日总结
    今天我把换乘查询的页面做了优化,主要体现在:优化之前,数据用的h1字体直接打印再页面之上的,显得很low,优化之后的效果是,我用模板直接把数据装进去了,更有美感。此外,我对前两个功......
  • 2023.3.19周报
    本周总结:刷了洛谷一些动态规划蓝题紫题大方向:动态规划小专题:树型DP、区间DP题目完成情况:15 ......