/** * 存储过程基本 * * @param processName --过程名 * @param paList --输入参数 * @param paTypeList --输入参数类型(默认Types.VARCHAR) * @param paInputList --IN(默认)/OUT类型 * @param rsType --封装游标集合的VO类型(默认HashMap) * @return * @throws Exception */ private static List executeProcess( String processName, List<Object> valueList, List<Integer> dbTypeList, List<Integer> inOutList, Class rsType, Connection con) throws Exception { // 1,参数检查 DBTool.checkProcessParameters(processName, valueList, dbTypeList, inOutList); // 2,处理过程 OracleCallableStatement call = null; try { // 2.1,获得Call call = (OracleCallableStatement) con.prepareCall(DBTool.GetCallString(processName, valueList)); // 2.2,绑定变量 if (valueList != null) { // "OUT"需要设定输出参数,"IN"需要输入参数绑定,"IN/OUT"全都需要 for (int i = 0; i < dbTypeList.size(); i++) { // Java对象 Object javaValue = valueList.get(i); // 需要对应的数据库类型 int db_type = dbTypeList.get(i); // 注册 DBTool.regedit(con, call, i + 1, javaValue, inOutList.get(i), db_type); } } /** ---------------后台打印---------------- */ P.printCall(DBTool.GetCallString(processName, valueList), valueList); /** ---------------后台打印---------------- */ // 3, 执行 call.execute(); // 4, 结果处理 for (int i = 0; i < valueList.size(); i++) if (inOutList.get(i) > C.CALL_PARAMETER_TYPE_IN) { Object obj = DBTool.GetJavaValueByDBMeta(call, dbTypeList.get(i), i + 1); if (obj.getClass() == ResultSet.class || dbTypeList.get(i) == OracleTypes.CURSOR) valueList.set(i, DBTool.GetRsList((ResultSet) obj, rsType)); else valueList.set(i, obj); } // 关闭存储过程默认的游标 call.close(); return valueList; } catch (Exception e) { throw e; } finally { if (call != null) call.close(); } }
/** * 函数(不考虑复杂的用法,只考虑函数的基本功能) * * @param callName --函数名称 * @param paList --输入参数 * @param returnType --返回种类 * @param rsClass --封装游标集合的类 * @return * @throws Exception */ private static Object executeFunction( String callName, List<Object> paList, int returnType, Class rsType, Connection con) throws Exception { OracleCallableStatement call = null; // 防止依赖注入 if (paList != null && paList.size() > 0) for (int i = 0; i < paList.size(); i++) if (paList.get(i) != null && paList.get(i).getClass() == String.class) if (((String) paList.get(i)).contains("'")) paList.set(i, UtilTool.ClearInfuse((String) paList.get(i))); // 执行函数的字符串 String CallFunction = "{? = " + DBTool.GetCallString(callName, paList).substring(1); try { call = (OracleCallableStatement) con.prepareCall(CallFunction); // 绑定变量,只考虑使用函数返回一个结果 "{?=" call.registerOutParameter(1, returnType); // 填充参数,注意从第2个"?"开始 List<Integer> paTypeList = DBTool.getPaTypeList(paList); for (int i = 0; paList != null && i < paList.size(); i++) DBTool.CallBindValue(con, call, paList.get(i), paTypeList.get(i), i + 2); /** ---------------*后台打印----------------------- */ P.printFunction(CallFunction, paList); /** ---------------*后台打印----------------------- */ // 执行 call.execute(); Object returnObj = DBTool.GetJavaValueByDBMeta(call, returnType, 1); if (returnObj.getClass() == ResultSet.class || returnType == OracleTypes.CURSOR) return DBTool.GetRsList((ResultSet) returnObj, rsType); else return returnObj; } catch (Exception e) { throw e; } finally { if (call != null) call.close(); } }