选择语句不返回任何值sqlite android

时间:2014-08-04 07:47:26

标签: android android-sqlite

我有sqlite数据库来存储和检索数据库中的信息。但是,当我想使用select语句从数据库中检索信息时,我不会为任何值进行调整????

代码

public class GroupDataBase extends SQLiteOpenHelper {

    private static final int dbVersion = 1;
    private static final String dbName = "HSsuraksha";
    private static final String grouptableName = "groupDetails";
    private static final String contacttableName = "contactDetails";
    private static final String groupId = "groupId";
    private static final String groupName = "groupName";
    private static final String createdOn = "createdOn";
    private static final String contactId = "contactId";
    private static final String contactGroupId = "groupId";
    private static final String contactName = "contactName";
    private static final String contactNumber = "contactNumber";
    private String groupIdValue;
    private SQLiteDatabase database;
    private ArrayList<String> groupIdList;
    private ArrayList<GroupModel> getGroupInfo;
    private static final String createContactTable = "Create Table " + contacttableName + "(" + contactId + " Integer Primary Key AutoIncrement," + contactGroupId + " Text," + contactName + " Text," + contactNumber + " Text" + ");";
    private static final String createGroupTable = "CREATE TABLE " + grouptableName + "(" + groupId + " Integer Primary Key AutoIncrement," + groupName + " Text," + createdOn + " Text" + ");";


    public GroupDataBase(Context context) {
        super(context, dbName, null, dbVersion);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {

        sqLiteDatabase.execSQL(createGroupTable);
        sqLiteDatabase.execSQL(createContactTable);

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {

//        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + contacttableName);
//        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + contacttableName);
//        onCreate(sqLiteDatabase);

    }

public void selectContacts(String id) {
        String query = "Select * From " + contacttableName + " where " + groupId + "=?";
        database = this.getWritableDatabase();
        Cursor cursor = database.rawQuery(query, new String[]{id});
        while (cursor.moveToNext()) {
            String contactNameValue = cursor.getString(cursor.getColumnIndexOrThrow(contactName));
            Log.e("Contact Name", "" + contactNameValue);
        }
        cursor.close();
        database.close();

    }

P.S-已在表中插入值

1 个答案:

答案 0 :(得分:1)

可能是您的查询中的问题 试试这个

String query = "Select * From " + contacttableName + " where " + groupId + " =? ";

如果这不起作用,请post Logcat个详细信息

希望它可以帮到你