我有这个SQL。
select sum(distance) AS distance FROM RoadTravelTableFile where checkBoxBusiness ='1' and plate_Number = 'AAA567'"
我在Ormlite文档中看到了对原始sql的这个简单查询。
long maxUnits = orderDao.queryRawValue("select max(units) from orders");
通过这个例子,我像这样编写了我的sql并且它可以工作。
distance = (int) getHelper().getRoadTravelTableFileIntegerDao().queryRawValue("SELECT SUM(distance) FROM RoadTravelTableFile where checkBoxBusiness = '1' and plate_Number ='AAA567' ");
但我有一个问题,你如何将checkBoxBusiness和plate_Number值作为参数?
答案 0 :(得分:1)
用?
替换当前值,并为queryRawValue方法添加参数。
Integer checkBoxBusiness = 1;
String plateNumber = "AAA567";
distance = (int) getHelper()
.getRoadTravelTableFileIntegerDao()
.queryRawValue("SELECT SUM(distance) FROM RoadTravelTableFile where checkBoxBusiness = ? and plate_Number = ?", checkBoxBusiness, plateNumber);