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

每日总结-23.3.23

时间:2023-03-23 21:11:22浏览次数:40  
标签:总结 cur 23 yonghuming con 23.3 new null String

关于数据库操作

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,23,yonghuming,con,23.3,new,null,String
From: https://www.cnblogs.com/laobing6214/p/17249456.html

相关文章

  • 20201230张国强实验二
    后门原理与实践1.基础问题回答(1)例举你能想到的一个后门进入到你系统中的可能方式?1.插入带毒的U盘,或者别人趁我不注意,插入带毒的U盘;2.下载盗版软件;3.钓鱼网站链接,利......
  • 2023年最新Webstorm免费安装教程
    前言WebStorm是JetBrains公司推出的一款专业的前端开发工具,它提供了丰富的功能和工具,能够帮助开发人员更快、更高效地开发Web应用程序。使用WebStorm,可以轻松创建和......
  • CVPR 2023 | 超越MAE!谷歌提出MAGE:图像分类和生成达到SOTA!
    前言 本文介绍了在一篇CVPR2023论文中,来自MIT和谷歌的研究人员提出了一种全新的框架MAGE,同时在图像识别和生成两大任务上实现了SOTA。本文转载自机器之心仅用于学......
  • 3.23总结
    <?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"androi......
  • 每日双人总结
    CREATETABLEbj_subway(station_idINTNOTNULLPRIMARYKEY,line_nameVARCHAR(20)NOTNULL,station_nameVARCHAR(50)NOTNULL,next_stationVARCHAR(......
  • 3.23每日总结
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtml><htmlxmlns="http://www.w3.org/1999/html">......
  • 【Java】关于Queue的用法总结
    【Java】关于Queue的用法总结原文链接:https://blog.csdn.net/qq_25353433/article/details/88016369之前对Queue只有一知半解,常用它的某几个方法,却不知道其中的区别,看了......
  • day23 打卡669. 修剪二叉搜索树 108.将有序数组转换为二叉搜索树 538.把二叉搜索树转
    day23打卡669.修剪二叉搜索树108.将有序数组转换为二叉搜索树538.把二叉搜索树转换为累加树669.修剪二叉搜索树669题目链接1.迭代法classSolution{public......
  • 阿里云可观测 2023 年 2 月产品月报
    ......
  • 今日总结
    今天把android端的北京地铁查询系统给完成了,主要功能实现了。学习时长:3小时,代码:360行,其中遇到了不少问题,在子线程设置settext会报错,再重写相同方法就可以了。toast也会报错......