Ich habe nicht viel Glück herauszufinden, wie man mit einem int und einem String abfragt. Ich habe Beispiele mit zwei Ints gefunden und Beispiele mit zwei Strings gefunden. Ich habe verschiedene Kombinationen ausprobiert und nichts scheint zu funktionieren. Im Folgenden sind zwei Beispiele von dem, was ich versucht habe und nicht gearbeitet habe. Was mache ich falsch. Ich habe sowohl inpspection_id als auch item_name selbst benutzt und beide funktionieren.Eine Abfrage mit einem int und einem String versuchen
1 Versuchen:
public int getId(int inspection_id ,String item_name)throws Exception
{
Cursor c = db.query(DB_TABLE, new String[] {KEY_INSPECTION_ID, KEY_ITEM_NAME},
"inspection_id=" + inspection_id +"item_name='"+ item_name + "'", null, null, null, null);
int id=c.getColumnIndex(KEY_ROWID);
c.moveToFirst();
String result=c.getString(id);
int primId=Integer.parseInt(result);
c.close();
return primId;
}
2 Versuchen:
public int getId(int inspection_id ,String item_name)throws Exception
{
Cursor c = db.query(DB_TABLE, new String[] {KEY_INSPECTION_ID, KEY_ITEM_NAME},
"inspection_id=" + inspection_id +"AND KEY_ITEM_NAME = ?", new String[]{item_name}, null, null, null);
int id=c.getColumnIndex(KEY_ROWID);
c.moveToFirst();
String result=c.getString(id);
int primId=Integer.parseInt(result);
c.close();
return primId;
}
3 Versuchen:
public int getId(int inspection_id ,String item_name)throws Exception
{
String s_id= Integer.toString(inspection_id);
Cursor c = db.query(DB_TABLE, new String[] {KEY_INSPECTION_ID, KEY_ITEM_NAME},
"KEY_INSPECTION_ID = ? AND KEY_ITEM_NAME = ?",
new String[] { s_id, item_name }, null, null, null);
int id=c.getColumnIndex(KEY_ROWID);
c.moveToFirst();
String result=c.getString(id);
int primId=Integer.parseInt(result);
c.close();
return primId;
}
Ich versuchte es und es hat nicht funktioniert – Aaron
Dank es etwas anderes entpuppte, aber wenn ich es geändert Kommentar gearbeitet – Aaron