09流程控制,while,for,continue,break
2015-08-17 16:47
501 查看
/**
* 执行存储过程
* @param 存储过程名称
* @param 所需参数
* @return 存储过程发返回的错误信息
* @author wuhao
* @throws Exception
*/
public static void executeProc(String call,Object[] params) throws Exception{
String result = "";
Connection conn = null;
CallableStatement proc = null;
try {
conn = dao.getSessionFactory().openSession().connection();
conn.setAutoCommit(false);
proc = conn.prepareCall(call);
int index = 0;
if(params != null && params.length > 0){
for (int i = 1; i <= params.length; i++) {
proc.setObject(i, params[i-1]);
index +=1;
}
}
index = index+1;
proc.registerOutParameter(index,Types.VARCHAR);
proc.execute();
result = proc.getString(index);
if( null != result && !result.equals("") ){
conn.rollback();
} else {
conn.commit();
}
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
if(null != proc)
proc.close();
if(null != conn)
conn.close();
}
}
* 执行存储过程
* @param 存储过程名称
* @param 所需参数
* @return 存储过程发返回的错误信息
* @author wuhao
* @throws Exception
*/
public static void executeProc(String call,Object[] params) throws Exception{
String result = "";
Connection conn = null;
CallableStatement proc = null;
try {
conn = dao.getSessionFactory().openSession().connection();
conn.setAutoCommit(false);
proc = conn.prepareCall(call);
int index = 0;
if(params != null && params.length > 0){
for (int i = 1; i <= params.length; i++) {
proc.setObject(i, params[i-1]);
index +=1;
}
}
index = index+1;
proc.registerOutParameter(index,Types.VARCHAR);
proc.execute();
result = proc.getString(index);
if( null != result && !result.equals("") ){
conn.rollback();
} else {
conn.commit();
}
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
if(null != proc)
proc.close();
if(null != conn)
conn.close();
}
}
相关文章推荐
- EasyUI 中combotree 默认不能选择父节点
- easyui datagrid 单元格编辑 自动聚焦 、全选
- UILabel使用自定义字体
- UIAutomator API浅析
- POJ 1019 Number Sequence (循环递增序列的的第K个值)
- POJ 1679 The Unique MST(判断最小生成树_Kruskal)
- 【CSS3 入门教程系列】CSS3 Media Queries 实现响应式设计
- 如何诊断RAC系统中的gc cr multi block request
- String,StringBuffer,StringBuilder以及线程安全性
- android stuio修改代码参考线和智能换行
- ArcServer10 安装中提示The following features cannot not be installed due to missing prerequisites"
- UITextView高度随文字自动增加
- iOS基础-UIKit框架-多控制器管理-实例:私人通讯录
- [LeetCode] Single Number III ( a New Questions Added today)
- android studio 新建项目 界面一直停在 【“building ‘ 项目名’ gradle project info”】
- UITableView使用详解
- [Leetcode] Longest Consecutive Sequence
- ZOJ 3210 A Stack or A Queue ? 水
- HDFS列式存储Parquet与行式存储(Avro)性能测试-Benchmark(hadoop, Spark, Scala)
- 【CF 570D】Tree Requests