问题描述
你好,我已经花了差不多2个小时试图弄清楚为什么LIKE语句不工作,我只收到此错误: 11月三号至3日:31:01.770:ERROR / AndroidRuntime(11767 ):由:android.database.sqlite.SQLiteException:绑定或列索引超出范围:办理0x89d9f8
Hello i've spent almost 2 hours trying to figure out why the LIKE statement doesn't work and i only get this error: 03-03 11:31:01.770: ERROR/AndroidRuntime(11767): Caused by: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x89d9f8
在的SQLiteManager它完全是这样的: SELECT字从注册WHERE字LIKE'他%';
但是,当我试图从Java做是行不通的。这里的是我的查询,我已经尝试了很多办法,没有运气:
In SQLiteManager it works perfectly like this: SELECT Word FROM Sign WHERE Word LIKE 'he%';
But when i try to do it from java it won't work.Here's is my query, i've tried in a lot of ways with no luck:
Cursor cursor = m_db.query(MY_TABLE, new String[] {"rowid","Word"},"Word"+" LIKE '"+" ?"+"%'", new String[]{name}, null, null, null);
任何想法?我是我做错了或者是有一个错误?
Any ideas? i'm i doing it wrong or is there a bug?
感谢您的时间。
推荐答案
我觉得你不应该使用selArgs像这样的方式。你可以试试这个:
I think you shouldn't use selArgs for LIKE such a way. You may try this:
Cursor cursor = m_db.query(MY_TABLE, new String[] {"rowid","Word"},"Word"+" LIKE '"+name+"%'", null, null, null, null);
编辑:
OK,如果你想从SQL注入安全,不要使用上面的解决方案,使用这样的:
OK, if you want be safe from SQL injections, don't use above solution, use this:
Cursor cursor = m_db.query(MY_TABLE, new String[] {"rowid","Word"},"Word LIKE '?'", new String[]{name+"%"}, null, null, null);
这篇关于SQLite的像android的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!