在原始SQL Ormlite传递参数 [英] Passing a parameter in Raw SQL Ormlite
本文介绍了在原始SQL Ormlite传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的SQL。
select sum(distance) AS distance FROM RoadTravelTableFile where checkBoxBusiness ='1' and plate_Number = 'AAA567'"
我已经看到了原始的SQL这个简单的查询Ormlite文件
I have seen this simple query for raw sql in the Ormlite document.
long maxUnits = orderDao.queryRawValue("select max(units) from orders");
通过这个例子,我codeD我这样的SQL和它的作品。
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' ");
不过,我有一个问题,你怎么能做出checkBoxBusiness和plate_Number值作为参数?
But I have a problem, How can you make the checkBoxBusiness and plate_Number value as a parameter?
推荐答案
替换
当前值,并添加参数到queryRawValue方法。
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);
这篇关于在原始SQL Ormlite传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文