废话就不多说了,开始。。。

1、Person

package com.njupt.sqlite;

public class Person {

	private Integer id;
private String name;
private Integer balance;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getBalance() {
return balance;
}
public void setBalance(Integer balance) {
this.balance = balance;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", balance=" + balance
+ "]";
}
public Person(Integer id, String name, Integer balance) {
super();
this.id = id;
this.name = name;
this.balance = balance;
} public Person() {
super();
} }

2、PersonDao

package com.njupt.sqlite;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; public class PersonDao { private DBOpenHelper helper; public PersonDao(Context context){
helper = new DBOpenHelper(context);
} public void insert(Person p){
SQLiteDatabase db = helper.getWritableDatabase(); db.execSQL("insert into person1(name,balance) values(?,?)",new Object[]{p.getName(),p.getBalance()});
db.close();
} public void delete(int id){
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL("delete from person1 where id = ?",new Object[]{id});
db.close();
} public void update(Person p){
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL("update person1 set name = ? , balance = ? where id = ?", new Object[]{p.getName(),p.getBalance(),p.getId()});
db.close();
} public Person query(int id){
SQLiteDatabase db = helper.getReadableDatabase();
Cursor c = db.rawQuery("select name ,balance from person1 where id = ?", new String[]{id + ""});
Person p = null; if(c.moveToNext()){
String name = c.getString(0);
int balance = c.getInt(1); p = new Person(id,name,balance);
} return p;
} }
    每日一道理
生活中受伤难免,失败跌倒并不可怕,可怕的是因此而一蹶不振,失去了对人生的追求与远大的理想。没有一个人的前进道路是平平稳稳的,就算是河中穿梭航行的船只也难免颠簸,生活中所遇上的坎坷磨难不是偶尔给予的为难,而是必然所经受的磨练。

3、DBTest

以下附上测试类

package com.njupt.sqlite;

import android.test.AndroidTestCase;

public class DBTest extends AndroidTestCase{

	public void test1(){
DBOpenHelper helper = new DBOpenHelper(getContext());
helper.getWritableDatabase(); } public void testInsert(){
PersonDao dao = new PersonDao(getContext()); Person p = new Person(3,"章泽天",45000); dao.insert(p);
} public void testDelete(){
PersonDao dao = new PersonDao(getContext()); int id = 1;
dao.delete(id);
} public void testUpdate(){
PersonDao dao = new PersonDao(getContext()); Person p = new Person(2,"lss",40000); dao.update(p); } public void testQuery(){
PersonDao dao = new PersonDao(getContext()); Person p = dao.query(3); System.out.println(p);
}
}

4、最后我们可以在SQLiteExpert中看到响应的变化

文章结束给大家分享下程序员的一些笑话语录:

人脑与电脑的相同点和不同点,人脑会记忆数字,电脑也会记忆数字;人脑会记忆程序,电脑也会记忆程序,但是人脑具有感知能力,这种能力电脑无法模仿,人的记忆会影响到人做任何事情,但是电脑只有程序软件。比尔还表示,人脑与电脑之间最重要的一个差别就是潜意识。对于人脑存储记忆的特别之处,比尔表示,人脑并不大,但是人脑重要的功能是联络,人脑会把同样的记忆存储在不同的地方,因此记忆读取的速度就不相同,而这种速度取决于使用的频率和知识的重要性。人脑的记忆存储能力会随着年龄增长而退化,同时记忆的质量也会随着年龄退化。经典语录网

---------------------------------
原创文章 By
crud和android
---------------------------------

crudandroidandroid——CRUD(在上一篇博客的基础上)的更多相关文章

  1. v79.01 鸿蒙内核源码分析(用户态锁篇) | 如何使用快锁Futex(上) | 百篇博客分析OpenHarmony源码

    百篇博客分析|本篇为:(用户态锁篇) | 如何使用快锁Futex(上) 进程通讯相关篇为: v26.08 鸿蒙内核源码分析(自旋锁) | 当立贞节牌坊的好同志 v27.05 鸿蒙内核源码分析(互斥锁) ...

  2. 接上一篇博客(解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match. )

    解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variabl ...

  3. 从SAP社区上的一篇博客开始,聊聊SAP产品命名背后的那份情怀

    最近Jerry在SAP社区上看到一篇博客:It's Steampunk now. 博客原文:https://blogs.sap.com/2019/08/20/its-steampunk-now/ 什么 ...

  4. 鸿蒙内核源码分析(根文件系统) | 先挂到`/`上的文件系统 | 百篇博客分析OpenHarmony源码 | v66.01

    百篇博客系列篇.本篇为: v66.xx 鸿蒙内核源码分析(根文件系统) | 先挂到/上的文件系统 | 51.c.h.o 文件系统相关篇为: v62.xx 鸿蒙内核源码分析(文件概念篇) | 为什么说一 ...

  5. VSCode上发布第一篇博客

    在VSCode上发布到博客园的第一篇博客 前段时间在VSCode安装好插件WriteCnblog,多次检查writeCnblog configuration配置信息也是完全正确的,但是一直没能在VSC ...

  6. 第一篇博客:Hello World

    2016年10月10日,双十,好日子,决定开始写第一篇博客,标题想了会,就叫Hello World 吧,哈哈^_^. 首先感谢博客园的管理们能批准我的申请,记得在14年的时候申请过一次,竟然没申请通过 ...

  7. 通通的最后一篇博客(附自制html5平面射击小游戏一枚)

    这是我最后一篇博客了,由于本人的人生规划吧,以后应该也写不出什么好的技术文章了,到现在在博客园写了2年, 今天一看,我也有了120个粉丝,好几万的浏览量,感谢大家的支持啊~~ 半年没有写博客了,由于半 ...

  8. 在腾讯云上部署Hexo博客

    推荐理由 ----搭建个人的空间博客目前深受个人开发者的追捧,然而博客的种类和平台有很多,Hexo是一个开源的静态博客生成器.相比于其他博客而言它只要是web容器就能用.除了闷头专研技术之外,程序员还 ...

  9. 在腾讯云上搭建WordPress博客

    笔者一直很羡慕那些搭建了个人博客的大牛,在最近工作之余也尝试着搭建了自己的博客,历时1周,这篇文章就将踩过的坑记录下来,先看下成果,链接在此 1- 购买腾讯云主机 腾讯云官网,我选了79元/月的最便宜 ...

随机推荐

  1. Javascript--dataTransfer

    描述: 提供对于预定义的剪贴板格式的访问,以便在拖拽中使用 属性 描述 参数 dropEffect[=sCursorStyle] 设置或获取拖拽操作的类型和要显示的光标类型 可选的copy 复制样式被 ...

  2. 间支付系统,DataGridView

    我们通常看到很多的学习使用控制数据库和接口连接--DataGridView,在我们的房间,当我们敲开使用第一遍阶段似该控件--MSHFlexGrid,随着学习的深入,发现我们用到的平台越来越人性化了, ...

  3. OCP-1Z0-051-题目解析-第10题

    10. View the Exhibit and examine the structure of the PROMOTIONS table. Each promotion has a duratio ...

  4. C语言实现全排列

    实现全排列,递归实现 #include <stdio.h> #include <stdlib.h> ; void swap(int *a, int *b) { int m; m ...

  5. leetcode第31题--Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  6. leetcode第七题--Reverse Integer

    Problem: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 ...

  7. 让你的ubuntu串口程序可以直接读写串口

    默认的情况下,如果我们使用一般用户去打开串口的话会出现 open failed 的错误 这个时候你可以在执行打开串口时加一个sudo,但每次这么需要这么干实在是太麻烦了. 这有一个方法可以跳过以超级用 ...

  8. 添加MySql Metat Database 信息

    有时候我们想看看 一个数据库上面 某种元素(比如表名)的所有信息,在Mysql上 我们可以通过引入information_schema 的方式,就可以非常方便的查看到. 添加步骤 Edit->P ...

  9. fscanf功能具体解释

    cfscanf fscanf fscanf : 格,fscanf格格 :int fscanf(FILE *stream, char *format,[argument...]); int fscanf ...

  10. Mysql高级之索引

    原文:Mysql高级之索引 索引:是针对数据所建立的目录. 作用: 可以加快查询速度 负面影响: 降低了增删改的速度. 索引的创建原则: 1:不要过度索引 2:在where条件最频繁的列上加.在重复度 ...