Android的SQLite的查询在哪里,在哪里 [英] Android SQLite Query Where and Where

查看:164
本文介绍了Android的SQLite的查询在哪里,在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数据库,在那里丹== table_column_one并在vrijeme == table_column_two返回ID值。我不知道如何做到这一点。

I need to return the ID value from the database where dan == table_column_one and where vrijeme == table_column_two. I don't know how to do this.

public static int returnID(String dan, int vrijeme){
        Cursor cursor;
        int IDRQ;
        cursor = db.query
                (
                        TABLE_NAME,
                        new String[] { TABLE_COLUMN_ID, TABLE_COLUMN_ONE, TABLE_COLUMN_TWO },                       
                        new String[] {TABLE_COLUMN_ONE + " like " + "'%" + dan + "%'", TABLE_COLUMN_TWO + " like " + "'%" + vrijeme + "%'"}, null, null, null, null
                );  
        cursor.moveToFirst();           
        IDRQ = cursor.getInt(0);
        return IDRQ;
    }   );  

这是我多努力,当然,它错了。

This is how I tried, but of course, its wrong.

推荐答案

在SQLiteDatabase.query()的选择有两个部分。在where子句(一个字符串)和whereArgs。(字符串的数组)

In SQLiteDatabase.query() the selection comes in two parts. The where clause (a String) and the whereArgs (an array of String).

要添加多个条件,where子句可以使用,就像&功放;&安培; || 中的Java

To add more than one condition to the where clause you can use AND or OR, just like && or || in Java.

在where子句中的问号绑定到字符串的whereArgs阵列中的一个。

A question mark in the where clause is bound to one of the Strings in the whereArgs array.

cursor = db.query(TABLE_NAME, new String[] { TABLE_COLUMN_ID, TABLE_COLUMN_ONE, TABLE_COLUMN_TWO },
TABLE_COLUMN_ONE + " LIKE ? AND " + TABLE_COLUMN_TWO + " LIKE ?",                           
new String[] {"%" + dan + "%", "%" + vrijeme + "%"},
null, null, null, null);

这篇关于Android的SQLite的查询在哪里,在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆