• JAVA日报


    从零开始的体温app开发(dao2)

    package dao;


    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;

    import bean.User;
    import bean.User2;
    import db.Sqlite;
    import db.Sqlite2;

    public class UserDao2 {
    private final Sqlite2 sqlite;
    private static UserDao2 userDao=null;
    private UserDao2(Context context){
    sqlite =new Sqlite2(context);
    }
    public static UserDao2 getInstance(Context context){
    if(userDao==null){
    userDao=new UserDao2(context);
    }
    return userDao;
    }
    //保存
    public void insert(User2 user){
    SQLiteDatabase db=sqlite.getWritableDatabase();
    ContentValues values=new ContentValues();
    values.put("num",user.getNum());
    values.put("name",user.getName());
    values.put("cl",user.getCl());
    values.put("phone",user.getPhone());
    db.insert("tex2",null,values);
    db.close();
    }
    //获取
    public boolean pkong(){
    boolean temp=false;
    SQLiteDatabase db=sqlite.getWritableDatabase();
    Cursor cursor=db.rawQuery("select *from tex2",null);
    if(cursor.getCount()!=0){
    temp=true;
    }
    return temp;
    }
    public List<User2> findAll(){
    SQLiteDatabase db=sqlite.getWritableDatabase();
    Cursor cursor=db.query("tex2",new String[]{"num","name","cl","phone"},null,null,null,null,null);
    List<User2> userList=new ArrayList<>();
    while(cursor.moveToNext()){
    User2 user2=new User2();
    user2.setNum(cursor.getString(0));
    user2.setName(cursor.getString(1));
    user2.setCl(cursor.getString(2));
    user2.setPhone(cursor.getString(3));
    //Log.e("sqliteshow",user.getName()+" "+user.getDate()+" "+user.getTime()+" "+user.getTem()+" "+user.getArea());
    userList.add(user2);
    }
    db.close();
    return userList;
    }
    }
  • 相关阅读:
    170322操作系统定义、功能、位置与历史
    java 多线程
    java 网络编程TCP程序设计
    java 事件处理机制
    java GUI编程
    170321php3第4章 PHP5的基本语法+作业九九乘法表
    170320网络编程 udpclient udpGroupClient
    二叉树线索化
    哈希表
    二叉搜索树
  • 原文地址:https://www.cnblogs.com/mumulailai/p/14909442.html
Copyright © 2020-2023  润新知