如何更新与ORMLite单引号的财产? [英] How update property with single quotes on ORMLite?
问题描述
当我尝试更新包含单引号的属性一个对象,发生错误类型:近阿瓜:语法错误
属性的值是:D'阿瓜
但ORM精简版使用单引号例如SQL:
更新'表'设置'值'='D'阿瓜
code的结果:
UpdateBuilder<表,整数GT; updateBuilder = tableDAO.updateBuilder();
尝试{
updateBuilder.updateColumnValue(价值,tableDTO.getDescricao());
updateBuilder.update();
}赶上(的SQLException E){
e.printStackTrace();
}
当我尝试更新包含单引号的属性一个对象,发生错误类型:近阿瓜:语法错误
块引用>这是一个常见问题。任何时候你可能有特殊字符在你的语句,你应该利用SQL
参数。随着 ORMLite ,则使用
SelectArg
类。排序因为它的一个不幸的名称的更新。SelectArg selectArg =新SelectArg(tableDTO.getDescricao());
updateBuilder.updateColumnValue(价值,selectArg);
updateBuilder.update();这将导致在SQL:
更新'表'设置'值'=?
然后字符串
D'阿瓜
将传递到update语句作为参数。</ P>经由在线文档的在查询中引号的搜索更多内容:
http://ormlite.com/docs/quotes-in-queries
块引用>When I try update a object with a property that contains single quote, happens error type: near "Agua": syntax error
The value of property is: "D'Agua"
But the orm lite make the sql with single quote as example:
UPDATE 'table' SET 'value' = 'D'Agua'
Result of code:
UpdateBuilder<Table, Integer> updateBuilder = tableDAO.updateBuilder(); try { updateBuilder.updateColumnValue("value", tableDTO.getDescricao()); updateBuilder.update(); } catch (SQLException e) { e.printStackTrace(); }
解决方案When I try update a object with a property that contains single quote, happens error type: near "Agua": syntax error
This is a FAQ. Anytime you might have special characters in your statements, you should leverage the SQL
?
arguments. With ORMLite, you use theSelectArg
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单引号的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!