Passing a parameter in Raw SQL Ormlite

2019-08-02 07:06发布

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条回答
你好瞎i
2楼-- · 2019-08-02 07:34

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);
查看更多
登录 后发表回答