package UIB.JHY; import java.sql.SQLException; import java.util.ArrayList; import CoreFS.SA01.CoreIComponent; import CoreFS.SA06.CoreReturnObject; import UIB.COM.XmlSqlParsersFactory; /** * * @desc * @author meiguiping * @date 2011 8:29:35 PM */ public class JHYComSave extends CoreIComponent { /** * @param list * 用1、 按照SQLID、其它参数顺序放入前台list * 用2、在ArrayList中加入ArrayList,后者与1相同,可一次执行多条SQL * @return * @throws Exception */ public CoreReturnObject doSimpleSave(ArrayList list) throws Exception { CoreReturnObject cro = new CoreReturnObject(); try { if(list == null) throw new Exception("错误,参数不允许为null!"); if(list.size() == 0) throw new Exception("错误,没有传入任何参数!"); if(list.get(0) instanceof ArrayList ) { int len = list.size(); for(int i = 0; i < len ; i++) { if(list.get(0) instanceof ArrayList) { doSimpleSave((ArrayList)list.get(i)); } else { throw new Exception("参数类型错误,请检查!"); } } } else { String sqlID = list.get(0).toString();//传入的第一个参数为SQL的ID if(list.size() == 1)//无参查询 { cro = this.ExcuteNoParameter(sqlID); } else//带参查询 { cro = this.ExcuteWithParameter(sqlID, list); } } }catch(Exception ex) { System.out.print("保存操作参数错误: "+ex.getMessage()); } return cro; } /** * @desc 带参数SQL * @param sqlID * @param list * @return * @throws SQLException */ private CoreReturnObject ExcuteWithParameter(String sqlID , ArrayList list)throws SQLException { CoreReturnObject cro = null; int len = list.size()-1; Object[] obj = new Object[len]; //System.out.println("list长度:"+list.size()); for(int i = 0; i < len; i++) { obj[i] = list.get(i+1).toString();//第0个参数为SQL语句,SQL语句中的参数需要从第一个开始 } cro = this.getDao("JhyDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID) , obj); return cro; } /** * @desc 无参数 * @param sqlID * @return * @throws SQLException */ private CoreReturnObject ExcuteNoParameter(String sqlID)throws SQLException { CoreReturnObject cro = null; cro = this.getDao("JhyDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID)); return cro; } }