java 如何在 Hibernate 查询中使用准备好的语句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26405116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use prepared statement in a Hibernate query?
提问by user3699218
How to use a prepared statement in a Hibernate query ?
如何在 Hibernate 查询中使用准备好的语句?
回答by Vicky Thakor
By default Hibernate uses PreparedStatement
. You don't have to worry about it. Not only Criteria
but Hibernate uses PreparedStatement
for createQuery
(HQL) and createSQLQuery
.
默认情况下,Hibernate 使用PreparedStatement
. 你不必担心。Criteria
Hibernate不仅PreparedStatement
用于createQuery
(HQL) 和createSQLQuery
.
Edit
编辑
Query spSQLQuery = session.createSQLQuery("SELECT * FROM user_master WHERE user_name = :param1");
spSQLQuery.setString("param1","vicky.thakor");
spSQLQuery.list();
Update
更新
Use setParameter
if setString
is not there in Query
interface.
使用setParameter
ifsetString
不在Query
界面中。
Thank you @Agricola for the update.
谢谢@Agricola 的更新。