zoukankan      html  css  js  c++  java
  • 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;
    }
    }
  • 相关阅读:
    003.同时Ping多个IP(select实现IO复用,信号计时),ping程序升级版
    002.ICMP--拼接ICMP包,实现简单Ping程序(原始套接字)
    001.linux下clock()检测程序运行时间
    django form的函数用法
    命令注入利用语句
    小白审计JACKSON反序列化漏洞
    代码审计小工具
    Burp插件开发--应用篇
    burp插件开发--基础篇
    JAVA web网站代码审计--入门
  • 原文地址:https://www.cnblogs.com/mumulailai/p/14909442.html
Copyright © 2011-2022 走看看