Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use rawQuery in android

Tags:

android

sql

I have a database table with 3 columns: id, name, permission.

It looks like this:

1 Comics fun

2 Communication talk

3 Comics watch

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";

and the method

public Cursor getData(){
        return db.rawQuery("SELECT permission FROM permissions_table WHERE name = 'Comics', null);
    }

and I'm calling this in my main class (safety.java). AppData is referencing AppData.java

appData.getData();

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.

like image 533
Hip Hip Array Avatar asked Apr 18 '11 18:04

Hip Hip Array


1 Answers

One typo mistake, you are not closing sql string with ". try this.

return db.rawQuery("SELECT permission FROM permissions_table WHERE name = 'Comics' ", null);

[EDIT: JAR belongs to 'Android 2.2' which does not allow modifications to source attachments on its entries]

The Jar of this class file blongs to container Android 2.0.1 which does not allow modifications

like image 185
Priyank Avatar answered Nov 12 '22 06:11

Priyank