Cursor cursor = db.rawQuery("select name from *** where id=?

", new String[]{"1"});

Cursor cursor = db.query("***", new String[]{"name"}, "id=?", new String[]{"1"}, null, null, null);



上面是两个各自是query和rawQuery的查询语句,主要差别是rawQuery是直接使用SQL语句进行查询的。也就是第一个參数字符串,在字符串内的“?”会被后面的String[]数组逐一对换掉。而query函数是Android自己封装的查询API:它的API文档例如以下:

public Cursor  query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) 



Query the given table, returning a Cursor over the result set.



table 

The table name to compile the query against. 



columns 

A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used. 



selection 

A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table. 



selectionArgs 

You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings. 



groupBy 

A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped. 



having 

A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used. 



orderBy 

How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered. 





Returns

•A Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.



而后者query对照前者来讲就有一个优点。前者rawQuery你在写入SQL语句的时候,有可能写错了或者写漏了什什么拼错的单词时,他将是错误的,而相对来说,后者的错误的机率是相当小

版权声明:本文博客原创文章。博客,未经同意,不得转载。

android rawquery和query对照的更多相关文章

  1. Android Permission中英对照

    android.permission.ACCESS_CHECKIN_PROPERTIESAllows read/write access to the "properties" t ...

  2. Android SQLiteDatabase中query、insert、update、delete方法参数说明

    1.SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selection, ...

  3. Android应用安全之Content Provider安全

    android平台提供了Content Provider,将一个应用程序的指定数据集提供给其它应用程序.这些数据可以存储在文件系统.SQLite数据库中,或以任何其它合理的方式存储.其他应用可以通过C ...

  4. Android SQLite (二) 基本用法

    在Android开发中SQLite起着很重要的作用,网上SQLite的教程有很多很多,不过那些教程大多数都讲得不是很全面.本人总结了一些SQLite的常用的方法,借着论坛的大赛,跟大家分享分享的. 一 ...

  5. 入門必學NO.1 Android 初學特訓班(第四版) 目錄

    第 01 章 敲開 Android 的開發大門工欲善其事,必先利其器,要學習 Android 應用程式,先取得功能強大的開發工具,就可讓學習事半功倍. 1.1 Android 是啥米?1.2 建構 A ...

  6. Android数据的四种存储方式

    作为一个完成的应用程序,数据存储操作是必不可少的.因此,Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File. ...

  7. android 数据库的增删改查

    主java package com.itheima.crud; import android.app.Activity; import android.content.Context; import ...

  8. Android开发_Android数据的四种存储方式

    Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File.由于Android系统中,数据基本都是私有的的,都是存放 ...

  9. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite

    SQLite是一种转为嵌入式设备设计的轻型数据库,其只有五种数据类型,分别是: NULL: 空值 INTEGER: 整数 REAL: 浮点数 TEXT: 字符串 BLOB: 大数据 在SQLite中, ...

随机推荐

  1. 按某个字段来分组、编号的row_number()函数

    本文参考 http://zhidao.baidu.com/link?url=8su4F16Et8Q0S3FmybwniJSI51Ms0AeVujcEXhyEaZh3u5LlOng5Xri_9zHsl7 ...

  2. REST WebService

    REST WebService 前置技能 ① 使用maven来管理java项目 这个技能必须点一级,以便快速配置项目. 本文实际上是我学习Spring的过程中搬的官网上的demo,使用maven配置项 ...

  3. php用空格代替标点符号

    php作为常规赛的符号替换为空格 <? php $character = "!@#$%^&*于'纸'纸'文().,<>|[]'\":;}{-_+=? /a ...

  4. 3.Chrome数据同步服务分析--server一片

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGVlcjE2OA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  5. 比ORA-24777: 我不使用不可移植数据库链接更郁闷的事情达成一致

    现场有一个同步误差,内容如下面:    java.sql.BatchUpdateException: ORA-24777: 不同意使用不可移植的数据库链路    at oracle.jdbc.driv ...

  6. python下载地址到迅雷qq旋风下载

    迅雷和qq旋风下载,有加速和离线功能,非常方面,我是在网上看到的原始地址和迅雷地址,qq旋风地址的转化原理.然后用python+pyqt写了一个client 原理: 迅雷: 迅雷下载地址=" ...

  7. Mule ESB-Content-Based Routing Tutorial(2)

    承接 Mule ESB-Content-Based Routing Tutorial(1) 五.执行应用程序  完毕创建,配置.并保存你的新的应用程序,您就能够在嵌入Mule的server上执行(包含 ...

  8. POJ 1066 Treasure Hunt(相交线段&amp;&amp;更改)

    Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...

  9. 微软将彻底改变Windows发布方式

    看到网上的新闻信息: 微软上任 CEO 史蒂夫·鲍尔默在职最后一段时间引入了更快的产品公布周期.不再向从前那样,每隔几年公布一次重大产品升级,而是功能一旦开发完成就会推送升级. 显然,现任 CEO 纳 ...

  10. strncpy和strcpy

    实体化代码运行图: 实现代码: #include <stdio.h> #include <string.h> #include <math.h> #include ...