Write a row query in Sqllite room

2020-05-08 07:03发布

I need to write this query by using sqllite room query with Dao Class. I.getItemID() is a dynamic variable.

"SELECT item_quantity FROM item WHERE item_id ='"+I.getItemID()+"'"

2条回答
够拽才男人
2楼-- · 2020-05-08 07:47

If it is what you meant, you almost got it then:

"SELECT item_quantity FROM item WHERE item_id = :I.getItemID()"
查看更多
Deceive 欺骗
3楼-- · 2020-05-08 07:57

Check out this link for more information regarding accessing-data using room.

@Dao
public interface MyDao {

    @Query("SELECT item_quantity FROM item WHERE item_id = :itemId")
    public int getItemQuantity(String itemId);

}
查看更多
登录 后发表回答