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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:53:07  来源:igfitidea点击:

How to use prepared statement in a Hibernate query?

javahibernate

提问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 Criteriabut Hibernate uses PreparedStatementfor createQuery(HQL) and createSQLQuery.

默认情况下,Hibernate 使用PreparedStatement. 你不必担心。CriteriaHibernate不仅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 setParameterif setStringis not there in Queryinterface.

使用setParameterifsetString不在Query界面中。

Thank you @Agricola for the update.

谢谢@Agricola 的更新。