sqlite - Android SQLiteDatabase query with WHERE clause -


i have sqlitedatabase called "database". in there table called "pics". in table there 3 columns follows, drawablename text,drawablereference integer,picturerating real. want query database integer expect in drawablereference column. want can corresponding drawablename , picturerating same row. wrong query?

public class edititemactivity extends activity {     edittext textfield=null;     ratingbar ratingbar=null;     sqlitedatabase db=null;     cursor dbcursor=null;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         intent intent=getintent();         integer imageid=intent.getintextra("imageid",-1);         if(imageid==-1){             return;         }         string id=imageid.tostring(); //not used right         setcontentview(r.layout.edit_item_layout);         db=this.openorcreatedatabase("database",this.mode_private,null);         string selection="drawablereference = ?";         string[] whereclause={id.tostring()};         dbcursor=db.query("pics",null,selection,whereclause,null,null,null);//get row correct drawablereference integer found         textfield=(edittext)findviewbyid(r.id.title);         ratingbar=(ratingbar)findviewbyid(r.id.image_rating_bar);         if(dbcursor.movetofirst()){             textfield.settext(dbcursor.getstring(0)); //this never happens         }     }  } 

try way:

    cursor dbcursor = db.rawquery("select drawablename,picturerating pics drawablereference='"+ id.tostring()+"'", null);      if(dbcursor.movetofirst()) {     textfield.settext(dbcursor.getstring(0));      } 

or

cursor cursor = db.query("pics", new string[] { "drawablename",         "picturerating" }, "drawablereference =?",         new string[] {id}, null, null, null, null); if (cursor.movetofirst())   textfield.settext(cursor.getstring(0));  } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -