有多个参数原料查询 [英] Raw query with multiple parameters

查看:108
本文介绍了有多个参数原料查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

preF_NAME,preF_STATUS - 文本

它给了我这个错误:

  07-02 14:08:07.457:E / AndroidRuntime(17295):android.database.sqlite.SQLiteException:?附近:语法错误:,在编译:SELECT?来自哪里?在哪里办理? =?

在code,我使用的是:

 光标C = db.rawQuery(选择?从何处?=?,新的String [] {preF_STATUS,
   preF_TABLE,preF_NAME,assigned_ pref_name});


解决方案

有根据<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery%28java.lang.String,%20java.lang.String%5B%5D%29\"相对=nofollow>文档,你只能把?在where子句:

 公共光标rawQuery(SQL字符串,字符串[] selectionArgs两个)参数
SQL中的SQL查询。 SQL字符串切不可;终止
selectionArgs两个你可以包含?s在查询中,将由来自selectionArgs两个值来代替条款。该值将被绑定为字符串。

PREF_NAME, PREF_STATUS - text

It gives me this error:

07-02 14:08:07.457: E/AndroidRuntime(17295): android.database.sqlite.SQLiteException: near "?": syntax error: , while compiling: SELECT ? FROM ? WHERE ? = ?

The code I'm using is:

Cursor c = db.rawQuery("SELECT ? FROM ? WHERE ? = ?", new String[]{ PREF_STATUS,
   PREF_TABLE, PREF_NAME, assigned_pref_name });

解决方案

According with the documentation, you only can put "?" on where clause:

public Cursor rawQuery (String sql, String[] selectionArgs)

Parameters
sql the SQL query. The SQL string must not be ; terminated
selectionArgs   You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.

这篇关于有多个参数原料查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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