本文介绍了如何更新与ORMLite单引号的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试更新包含单引号的属性一个对象,发生错误类型:近阿瓜:语法错误
属性的值是:D'阿瓜
但ORM精简版使用单引号例如SQL:
更新'表'设置'值'='D'阿瓜
code的结果:
UpdateBuilder<表,整数GT; updateBuilder = tableDAO.updateBuilder();
尝试{
updateBuilder.updateColumnValue(价值,tableDTO.getDescricao());
updateBuilder.update();
}赶上(的SQLException E){
e.printStackTrace();
}
解决方案
This is a FAQ. Anytime you might have special characters in your statements, you should leverage the SQL ?
arguments. With ORMLite, you use the SelectArg
class. Sort of an unfortunate name given that its an update.
SelectArg selectArg = new SelectArg(tableDTO.getDescricao());
updateBuilder.updateColumnValue("value", selectArg);
updateBuilder.update();
This will result in the SQL:
UPDATE 'table' SET 'value' = ?
Then the string "D'Agua"
will be passed into the update statement as an argument.
More on this via a search for "quotes in queries" in the online docs:
这篇关于如何更新与ORMLite单引号的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!