• 个人作业通讯录


    通讯录

    这个小软件是我自己在家时候学习sqlite增删改查的时候写的,这个小app主要实现的一个是记住密码的功能,还有将照片存储在数据库中的具体操作的过程值得去仔细体验。

            

                       

    代码展视:

    package com.example.tongxunlu.dao;

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

    import com.example.tongxunlu.db.AppSqliteHelper;
    import com.example.tongxunlu.model.User;

    public class UserDao {
        private AppSqliteHelper helper;
        private String tablename = "user";

        public UserDao(Context context){
            helper = new AppSqliteHelper(context);
        }

        //登录
        public User login(String account,String password){
            SQLiteDatabase db = helper.getReadableDatabase();
            Cursor c = db.query(tablename,null,"name=? and password=?",new String[]{account,password},null,null,null,null);
           User user = null;
            if(c!= null&&c.getCount()>0){
                if(c.moveToNext()){
                    user = new User();
                    user.setId(c.getInt(c.getColumnIndex("id")));
                    user.setName(account);
                    user.setPassword(password);
                    user.setPhone(c.getString(c.getColumnIndex("phone")));

                }
            }
            return user;
        }
        //根据账号和手机号判断用户是否存在
        public boolean isExistByAccountAndPhone(String account,String phone){
            SQLiteDatabase db = helper.getReadableDatabase();
            Cursor c = db.query(tablename,null,"name=? or phone=?",new String[]{account,phone},null,null,null,null);
            if(c!= null&&c.getCount()>0){

                    return c.moveToNext();
            }
            return false;
        }
        //注册
        public boolean insert(User bean){
            SQLiteDatabase db = helper.getWritableDatabase();
            ContentValues values = new ContentValues();
            values.put("name",bean.getName());
            values.put("password",bean.getPassword());
            values.put("phone",bean.getPhone());
            long insert = db.insert(tablename,null,values);
            return insert >0;
        }

        //根据账号或手机号查询密码
        public  String queryPasswordByAccountAndPhone(String account,String phone){
            SQLiteDatabase db = helper.getReadableDatabase();
            Cursor c = db.query(tablename,null,"name=? and phone=?",new String[]{account,phone},null,null,null,null);
            if(c != null && c.getCount()>0){
                if(c.moveToNext()){
                    return(c.getString(c.getColumnIndex("password")));
                }
            }
            return null;
        }


    }

  • 相关阅读:
    一些开发海学网站过程中的Javascript
    准备学习 Windows Forms 2.0 Programming
    终于买了个Dell d400二手笔记本
    Asp.Net应用程序中为什么要MachineKey?如何生成MachineKey?
    今天装了苏州数字电视
    windows Forms 编程实战 源代码
    重新整理 .net core 实践篇——— filter[四十四]
    not noly go —— 运行轨迹[一]
    .NET CLR基本术语
    [转]SqlServer四个排名函数(row_number、rank、dense_rank和ntile)的比较
  • 原文地址:https://www.cnblogs.com/wfswf/p/14908414.html
Copyright © 2020-2023  润新知