android - Method query db to return results -
this question has answer here:
- method excute query , return results 1 answer
app won't run. occurs recurrently:
04-05 21:29:09.570: e/androidruntime(1069): caused by: java.lang.illegalargumentexception: cannot bind argument @ index 1 because index out of range. statement has 0 parameters. main - calling method
cursor wow = db.trying("gold"); text = (textview) findviewbyid(r.id.textview13); string quantity = wow.getstring(0); // text.settext(quantity); db handler - method
public cursor trying(string vg){ string q = "select quantity " + table_contacts + " name=" + "'" + vg +"'"; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(q, new string[] {vg}); if (cursor != null) { cursor.movetofirst(); } return cursor; }
the problem is
string q = "select quantity " + table_contacts + " name=" + "'" + vg +"'"; in query had specify parameter condition .after again passing query
cursor cursor = db.rawquery(q, new string[] {vg}); this makes confusion .so try change query
string q = "select quantity " + table_contacts + " name = ?"; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(q, new string[] {vg}); or go approach
string q = "select quantity " + table_contacts + " name=" + "'" + vg +"'"; cursor cursor = db.rawquery(q, null); if(cursor != null && cursor.getcount()>0){ cursor.movetofirst(); //do action //fetch data } else { toast.maketext(getbasecontext(), "no records yet!", toast.length_short).show(); return; }
Comments
Post a Comment