下面的这个是调用Oracle的Java代码,现在我不知道怎么改成调用MySQL存储过程的代码?求大神指点
publicStringaddVendor(TvendorTvendor,Fauseruser){//TODOAuto-generatedmethodstubTransa...
public String addVendor(Tvendor Tvendor, Fauser user) {
// TODO Auto-generated method stub
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
String msg="";
try{
baseTransaction.save(Tvendor);
sessionFactory.getCurrentSession().flush();
final Long argsGid = Long.valueOf(Tvendor.getFgid());
final Long fcreator = Long.valueOf(user.getGid());
System.out.println(argsGid+"--"+fcreator);
Map result = null;
boolean b = true;
// result=getResultData(argsGid,fcreator);
String procedure = "{? = call PWM_VENDOR.ON_ADDNEW(?,?,?)}";
try{
result = (java.util.Map) jdbcTemplate.execute(procedure,
new CallableStatementCallback() {
@Override
public Map doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
// 返回参数 注册一下,这样后面才能取到
cs.registerOutParameter(1, Types.INTEGER);
cs.setLong(2, argsGid); // 设置参数
cs.setLong(3, fcreator); // 设置参数
cs.registerOutParameter(4, Types.LONGVARCHAR);
cs.execute(); // 执行
// 返回值
int resInt1 = cs.getInt(1);
// 出错信息
String resInt4 = cs.getString(4);
Map result = new HashMap<String, Object>();
result.put("flag", resInt1);
result.put("errorMsg", resInt4);
System.out.println("1-->" + resInt1);
System.out.println("4-->" + resInt4);
return result;
}
});
if (!"0".equals(result.get("flag").toString()) ){
transactionManager.rollback(status);
}else{
transactionManager.commit(status);
}
}catch(Exception e){
e.printStackTrace();
b = false;
msg="保存失败:数据库函数出错了 ";
}
if (result != null) {
if ("1".equals(result.get("flag").toString())) {
b = false;
msg="保存失败: "
+ result.get("errorMsg").toString();
} 展开
// TODO Auto-generated method stub
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
String msg="";
try{
baseTransaction.save(Tvendor);
sessionFactory.getCurrentSession().flush();
final Long argsGid = Long.valueOf(Tvendor.getFgid());
final Long fcreator = Long.valueOf(user.getGid());
System.out.println(argsGid+"--"+fcreator);
Map result = null;
boolean b = true;
// result=getResultData(argsGid,fcreator);
String procedure = "{? = call PWM_VENDOR.ON_ADDNEW(?,?,?)}";
try{
result = (java.util.Map) jdbcTemplate.execute(procedure,
new CallableStatementCallback() {
@Override
public Map doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
// 返回参数 注册一下,这样后面才能取到
cs.registerOutParameter(1, Types.INTEGER);
cs.setLong(2, argsGid); // 设置参数
cs.setLong(3, fcreator); // 设置参数
cs.registerOutParameter(4, Types.LONGVARCHAR);
cs.execute(); // 执行
// 返回值
int resInt1 = cs.getInt(1);
// 出错信息
String resInt4 = cs.getString(4);
Map result = new HashMap<String, Object>();
result.put("flag", resInt1);
result.put("errorMsg", resInt4);
System.out.println("1-->" + resInt1);
System.out.println("4-->" + resInt4);
return result;
}
});
if (!"0".equals(result.get("flag").toString()) ){
transactionManager.rollback(status);
}else{
transactionManager.commit(status);
}
}catch(Exception e){
e.printStackTrace();
b = false;
msg="保存失败:数据库函数出错了 ";
}
if (result != null) {
if ("1".equals(result.get("flag").toString())) {
b = false;
msg="保存失败: "
+ result.get("errorMsg").toString();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询