用谷歌封装好的API进行数据库增删查改(crud)
2016-01-30 14:56
489 查看
谷歌API
优点:
[1]写法简单,不易写错
[2]有返回值,方便开发,有提示
缺点:
[1]不够灵活,多张表时不易查询
优点:
[1]写法简单,不易写错
[2]有返回值,方便开发,有提示
缺点:
[1]不够灵活,多张表时不易查询
//sql语句增加一条记录 db.execSQL("insert into info(name,phone) values(?,?)",new Object[]{"小明","110"});
//API增加一条记录 ContentValues values = new ContentValues(); values.put("name","小明"); values.put("phone", "110"); long insert = db.insert("info", null, values); if (insert > 0) { Toast.makeText(getApplicationContext(), "插入成功", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),"插入失败",Toast.LENGTH_LONG).show(); }
//sql语句删除 db.execSQL("delete from info where name=?",new Object[]{"小明"});
//API删除 int delete = db.delete("info", "name=?", new String[]{"小明"}); Toast.makeText(MainActivity.this,"删除了"+delete+"行",Toast.LENGTH_LONG).show();
//sql语句更新 db.execSQL("update info set phone=? where name=?",new Object[]{"120","小明"});
//API更新 ContentValues values = new ContentValues(); values.put("phone", "120"); int updata = db.update("info", values, "name=?", new String[]{"小明"}); Toast.makeText(MainActivity.this, "更新了" + updata + "行", Toast.LENGTH_LONG).show();
//sql语句查询 Cursor cursor = db.rawQuery("select * from info", null);
//API查询 Cursor cursor = db.query("info", null, "name=?", new String[]{"小明"}, null, null, null);
相关文章推荐
- Android Manifest 用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Python动态类型的学习---引用的理解
- 什么是 GraphQL?
- Spark RDD API详解(一) Map和Reduce
- 数据库链接字符串查询网站
- 谷歌正式开始补偿Nexus 6P重启门和电池门用户:最高赔400美元
- DB2实例管理
- DB2实例管理
- 保障MySQL数据安全的14个最佳方法
- mysql问答汇集
- 创建一个空的IBM DB2 ECO数据库的方法
- 土人系列AS入门教程 -- 对象篇
- Access 2000 数据库 80 万记录通用快速分页类
- 开通一个数据库失败的原因的和解决办法
- 一个简单的asp数据库操作类
- 一个小型js框架myJSFrame附API使用帮助
- CentOS下DB2数据库安装过程详解
- EasyASP v1.5发布(包含数据库操作类,原clsDbCtrl.asp)第1/2页