Android——SQLDataBase操作
来源:互联网 发布:网络打印机 脱机 编辑:程序博客网 时间:2024/06/06 01:37
安卓数据库相关操作
转载自http://www.cnblogs.com/maxinliang/archive/2013/01/22/2871474.html
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs,String groupBy, String having,String orderBy,String limit)
table (要查询的表名.)
columns (想要显示的列,若为空则返回所有列,不建议设置为空,如果不是返回所有列)
selection (where子句,声明要返回的行的要求,如果为空则返回表的所有行。)
selectionArgs ( where子句对应的条件值)
groupBy (分组方式,若为空则不分组.)
having (having条件,若为空则返回全部(不建议))
orderBy (排序方式,为空则为默认排序方式)
limit (限制返回的记录的条数,为空则不限制)
Returns
A Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.
示例:
ContentValues cv = new ContentValues();
String[] args = {String.valueOf("a")};
query("user", new String[] { "username","password" },"username=?", args, null,null, null, null);
SQLiteDataBase对象的insert()接口:
public long insert (String table, String nullColumnHack, ContentValues values)
table (要插入数据的表的名称)
nullColumnHack ( 当values参数为空或者里面没有内容的时候,我们insert是会失败的(底层数据库不允许插入一个空行),为了防止这种情况,我们要在这里指定一个 列名,到时候如果发现将要插入的行为空行时,就会将你指定的这个列名的值设为null,然后再向数据库中插入。)
values (一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
Returns
the row ID of the newly inserted row, or -1 if an error occurred
示例:
ContentValues cv = new ContentValues();
cv.put("username", "a");
cv.put("password", "b");
insert("user", null, cv);
SQLiteDataBase对象的update()接口:
public int update (String table, ContentValues values, String whereClause, String[] whereArgs)
Convenience method for updating rows in the database.
table (要更新的表名)
values (一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
whereClause (可选的where语句)
whereArgs(whereClause语句中表达式的?占位参数列表)
Returns
the number of rows affected
ContentValues cv = new ContentValues();
cv.put("username", "c");
cv.put("password", "d");
String[] args = {String.valueOf("a")};
update("user", cv, "username=?",args)
SQLiteDataBase对象的delete()接口:
public int delete (String table, String whereClause, String[] whereArgs)
Convenience method for deleting rows in the database.
table (表名)
whereClause(whereClause语句中表达式的?占位参数列表)(可选的where语句)
whereArgs (可选的where语句)
Returns
the number of rows affected if a whereClause is passed in, 0 otherwise. To remove all rows and get a count pass "1" as the whereClause.
示例:
ContentValues cv = new ContentValues();
String[] args = {String.valueOf("c")};
delete("user", "username=?", args);
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs,String groupBy, String having,String orderBy,String limit)
table (要查询的表名.)
columns (想要显示的列,若为空则返回所有列,不建议设置为空,如果不是返回所有列)
selection (where子句,声明要返回的行的要求,如果为空则返回表的所有行。)
selectionArgs ( where子句对应的条件值)
groupBy (分组方式,若为空则不分组.)
having (having条件,若为空则返回全部(不建议))
orderBy (排序方式,为空则为默认排序方式)
limit (限制返回的记录的条数,为空则不限制)
Returns
A Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.
示例:
ContentValues cv = new ContentValues();
String[] args = {String.valueOf("a")};
query("user", new String[] { "username","password" },"username=?", args, null,null, null, null);
SQLiteDataBase对象的insert()接口:
public long insert (String table, String nullColumnHack, ContentValues values)
table (要插入数据的表的名称)
nullColumnHack ( 当values参数为空或者里面没有内容的时候,我们insert是会失败的(底层数据库不允许插入一个空行),为了防止这种情况,我们要在这里指定一个 列名,到时候如果发现将要插入的行为空行时,就会将你指定的这个列名的值设为null,然后再向数据库中插入。)
values (一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
Returns
the row ID of the newly inserted row, or -1 if an error occurred
示例:
ContentValues cv = new ContentValues();
cv.put("username", "a");
cv.put("password", "b");
insert("user", null, cv);
SQLiteDataBase对象的update()接口:
public int update (String table, ContentValues values, String whereClause, String[] whereArgs)
Convenience method for updating rows in the database.
table (要更新的表名)
values (一个ContentValues对象,类似一个map.通过键值对的形式存储值。)
whereClause (可选的where语句)
whereArgs(whereClause语句中表达式的?占位参数列表)
Returns
the number of rows affected
ContentValues cv = new ContentValues();
cv.put("username", "c");
cv.put("password", "d");
String[] args = {String.valueOf("a")};
update("user", cv, "username=?",args)
SQLiteDataBase对象的delete()接口:
public int delete (String table, String whereClause, String[] whereArgs)
Convenience method for deleting rows in the database.
table (表名)
whereClause(whereClause语句中表达式的?占位参数列表)(可选的where语句)
whereArgs (可选的where语句)
Returns
the number of rows affected if a whereClause is passed in, 0 otherwise. To remove all rows and get a count pass "1" as the whereClause.
示例:
ContentValues cv = new ContentValues();
String[] args = {String.valueOf("c")};
delete("user", "username=?", args);
阅读全文
0 0
- Android——SQLDataBase操作
- Android SQLDatabase类中的in…
- Android——文件操作
- Android——按钮操作
- Android——文件操作
- SQLite操作——Android
- android学习——HttpClient 操作 模拟 http 操作
- android开发数据操作(二)——ContentProvider操作实例
- Android文件操作 —— 6.0之后文件操作
- Android开发之——Menu 操作
- Android开发——文件操作模式
- Android开发——文件操作模式
- Android——sqlite3 基本命令操作
- Android之——ContentProvider操作XML
- Android——操作摄像头、图片合成
- Android Notification 详解——基本操作
- Android之Bluetooth—蓝牙操作
- Android——Android实现多级菜单联动操作
- status bar改变字体颜色
- x264参数介绍(二 ,分析和视频可用性信息)
- php curl支持302域名跳转
- 【详细内容】宏晶微MS1820规格书Ypbpr/VGA/TTL互转
- XStream使用详解
- Android——SQLDataBase操作
- html长英文换行
- iOS XCode 编译按钮 clean 灰色 不能点击
- 文件上传与下载--servlet版本上传
- MySQL高级 之 锁
- Win10(64bit)+Emgu CV3.0.0+VS2013 下载&安装&配置
- android EasyRxRetrofit封装(包括上传下载及进度监听)
- AUC计算方法总结
- 黑色帽子