Passing a parameter in Raw SQL Ormlite

旧街凉风 提交于 2019-12-13 01:27:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!