问题
I have this SQL.
select sum(distance) AS distance FROM RoadTravelTableFile where checkBoxBusiness ='1' and plate_Number = 'AAA567'"
I have seen this simple query for raw sql in the Ormlite document.
long maxUnits = orderDao.queryRawValue("select max(units) from orders");
With that example, I coded my sql like this and it works.
distance = (int) getHelper().getRoadTravelTableFileIntegerDao().queryRawValue("SELECT SUM(distance) FROM RoadTravelTableFile where checkBoxBusiness = '1' and plate_Number ='AAA567' ");
But I have a problem, How can you make the checkBoxBusiness and plate_Number value as a parameter?
回答1:
Replace current values with ?
and add arguments to the queryRawValue method.
Integer checkBoxBusiness = 1;
String plateNumber = "AAA567";
distance = (int) getHelper()
.getRoadTravelTableFileIntegerDao()
.queryRawValue("SELECT SUM(distance) FROM RoadTravelTableFile where checkBoxBusiness = ? and plate_Number = ?", checkBoxBusiness, plateNumber);
来源:https://stackoverflow.com/questions/25736056/passing-a-parameter-in-raw-sql-ormlite