本文介绍了createStoredProcedureQuery 未解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,createStoredProcedureQuery在eclipse下面有红线,没有解决,我尝试了很多方法仍然找不到问题所在.
here is my code and createStoredProcedureQuery has redline underneath in eclipse, and not resolved, I tried many ways still could not get what is wrong.
private static EntityManagerFactory factory;
public static void main(String[] args) {
factory = Persistence.createEntityManagerFactory("mypersistenceUnit");
EntityManager em = factory.createEntityManager();
// Create call stored procedure
em.getTransaction().begin();
StoredProcedureQuery storedProcedure = em.**createStoredProcedureQuery**("getCode");
// set parameters
storedProcedure.registerStoredProcedureParameter("name", String.class, ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("num", String.class, ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("code", String.class, ParameterMode.OUT);
// execute SP
storedProcedure.execute();
// get result
String code= (String)storedProcedure.getOutputParameterValue("code");
System.out.println("code is: " + code);
em.getTransaction().commit();
em.close();
}
推荐答案
需要声明和设置参数:
/*Declare parameters*/
storedProcedure.registerStoredProcedureParameter( "name", String.class,ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter( "num", String.class,ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("code", String.class, ParameterMode.OUT);
/*set parameter value*/
storedProcedure.setParameter("name", "value_name");
storedProcedure.setParameter("num", "value_num");
storedProcedure.execute();
// get result
String code= (String)storedProcedure.getOutputParameterValue("code");
--记住,存储过程中的参数名必须与声明的一致
--remember, the parameters name in the store procedure must be the same to declared
这篇关于createStoredProcedureQuery 未解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!