如何使用rawQuery在android系统 [英] how to use rawQuery in android
问题描述
我有一个数据库表3列:ID,名称,批准
I have a database table with 3 columns: id, name, permission.
它看起来是这样的:
1有趣的漫画
2的通信对话
3看漫画
我试图让那里的名字是漫画的权限。我使用下面的code在我的数据库类(AppData.java):
I am trying to get the permission where the name is comics. I am using the following code in my database class(AppData.java):
private final static String DB_NAME = "safety_app_database"; // the name of our database
private final static int DB_VERSION = 1; // the version of the database
// the names for our database columns
private final String TABLE_NAME = "permissions_table";
private final String ID = "id";
private final String NAME = "name";
private final String PERMISSION = "permission";
和方法
public Cursor getData(){
return db.rawQuery("SELECT permission FROM permissions_table WHERE name = 'Comics', null);
}
和我在我的主类(safety.java)调用此。 AppData的是引用AppData.java
and I'm calling this in my main class (safety.java). AppData is referencing AppData.java
appData.getData();
这是做了正确的方法是什么?我不确定,这是给我一个错误,每当我尝试调用SQL查询。
Is this the correct way to do it? I am unsure, and it is giving me an error whenever I try to call the sql query.
推荐答案
一个错字错,你不关闭SQL字符串。试试这个。
One typo mistake, you are not closing sql string with "
. try this.
return db.rawQuery("SELECT permission FROM permissions_table WHERE name = 'Comics' ", null);
<一个href=\"http://stackoverflow.com/questions/2064100/the-jar-of-this-class-file-blongs-to-container-android-2-0-1-which-does-not-allow\">The这个类文件blongs到容器的Android 2.0.1不允许修改
这篇关于如何使用rawQuery在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!