[英]How to call a Oracle stored procedure from java hibernate with 6 input parameters and 6 output parametrs?
I am extending StoredProcedure class of spring framework and i don't know how to set the input parameters and output parameters!! 我正在扩展spring框架的StoredProcedure类,我不知道如何设置输入参数和输出参数!
package com.test.schedular.dao;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import oracle.jdbc.driver.OracleTypes;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;
import org.springframework.stereotype.Repository;
import com.mobicule.customer.bean.CustomerTransaction;
@Repository
public class CustomerTransactionSchedularDao extends StoredProcedure implements ICustomerTransactionSchedularDao
{
@Autowired
SessionFactory sessionFactory;
private static final String SPROC_NAME = "procedure_name";
CustomerTransactionSchedularDao(DataSource dataSource)
{
super(dataSource, SPROC_NAME);
declareParameter(new SqlOutParameter("v_dedup_key1", OracleTypes.VARCHAR));
declareParameter(new SqlOutParameter("v_dedup_key2", OracleTypes.VARCHAR));
declareParameter(new SqlOutParameter("v_dedup_key3", OracleTypes.VARCHAR));
declareParameter(new SqlOutParameter("v_dedup_key4", OracleTypes.VARCHAR));
declareParameter(new SqlOutParameter("v_dedup_key6", OracleTypes.VARCHAR));
declareParameter(new SqlOutParameter("v_dedup_key7", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("v_first_name", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("v_last_name", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("v_mother_maiden_name", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("v_dob", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("v_realted_corp_party_id", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("v_req_effective_date", OracleTypes.VARCHAR));
compile();
}
@Override
public void callSyn_P_Get_Dedup_Key(CustomerTransaction customerTransaction)
{
Session session = sessionFactory.openSession();
/*Query query = session.createSQLQuery("CALL syn_p_get_dedup_key(:v_first_name, :v_last_name, :v_mother_maiden_name,"
+ ":v_dob, :v_realted_corp_party_id, :v_req_effective_date )"
+ " :v_dedup_key1,:v_dedup_key2,:v_dedup_key3,:v_dedup_key4,:v_dedup_key6,:v_dedup_key7)")
.addScalar("v_dedup_key1", StandardBasicTypes.STRING )
.addScalar("v_dedup_key2", StandardBasicTypes.STRING )
.addScalar("v_dedup_key3", StandardBasicTypes.STRING )
.addScalar("v_dedup_key4", StandardBasicTypes.STRING )
.addScalar("v_dedup_key6", StandardBasicTypes.STRING )
.addScalar("v_dedup_key7", StandardBasicTypes.STRING )
.setParameter("v_first_name", customerTransaction.getFirstName())
.setParameter("v_last_name", customerTransaction.getLastName())
.setParameter("v_mother_maiden_name",customerTransaction.getMothersMaidenName())
.setParameter("v_dob", customerTransaction.getDateOfBirth())
.setParameter("v_realted_corp_party_id", null)
.setParameter("v_req_effective_date", null);*/
Map<String, Object> inParams = new HashMap<String, Object>(2);
inParams.put("v_first_name", "");
inParams.put("v_last_name", "");
inParams.put("v_mother_maiden_name", "");
inParams.put("v_dob","");
inParams.put("v_realted_corp_party_id", "");
inParams.put("v_req_effective_date", "");
Map<String,Object> m = execute(inParams);
System.out.println(m);
/*List result = query.list();
System.out.println(result);*/
}
}
How to call a stored procedure in hibernate who has 6 input and 6 output parameters in its syntax.? 如何在其语法中具有6个输入和6个输出参数的hibernate中调用存储过程?
First of all StoredProcedure
- a spring class, not a hibernate class. 首先是
StoredProcedure
一个Spring类,而不是一个Hibernate类。
final Map<String, Object> inParams = new HashMap<String, Object>(6);
inParams.put("v_first_name", "");
inParams.put("v_last_name", "");
inParams.put("v_mother_maiden_name", "");
inParams.put("v_dob","");
inParams.put("v_realted_corp_party_id", "");
inParams.put("v_req_effective_date", "");
final Map<String, Object> result = execute(inParams);
System.out.println("v_dedup_key1 = [" + result.get("v_dedup_key1") + ']');
System.out.println("v_dedup_key2 = [" + result.get("v_dedup_key2") + ']');
System.out.println("v_dedup_key3 = [" + result.get("v_dedup_key3") + ']');
System.out.println("v_dedup_key4 = [" + result.get("v_dedup_key4") + ']');
System.out.println("v_dedup_key5 = [" + result.get("v_dedup_key5") + ']');
System.out.println("v_dedup_key6 = [" + result.get("v_dedup_key6") + ']');
Did you try to execute the code like this? 您是否尝试过执行这样的代码?
in Hibernate 在休眠状态
String v_param_1 = "param_1";
SessionImpl session = (SessionImpl) sessionFactory.openSession();
CallableStatement callableStatement = session.connection().prepareCall("call P_MYSTORE(?,?)");
callableStatement.setString(1, v_param_1);
callableStatement.registerOutParameter(2, OracleTypes.VARCHAR);
callableStatement.execute();
//get out param from store
String v_param_2 = callableStatement.getString(2);
store procedure in oracle 在oracle中存储过程
CREATE OR REPLACE PROCEDURE P_MYSTORE(p_in_1 in varchar2, p_out_1 out varchar2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.