package UIB.JHY; import CoreFS.SA01.CoreIComponent; import CoreFS.SA06.CoreReturnObject; import UIB.COM.XmlSqlParsersFactory; import java.sql.SQLException; import java.util.ArrayList; public class ComSave extends CoreIComponent { /** * @param list 用1、 按照SQLID、其它参数顺序放入前台list * 用2、在ArrayList中加入ArrayList,后者与1相同,可一次执行多条SQL * @return * @throws Exception */ public CoreReturnObject doSimpleSave(String dao, 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(dao, (ArrayList) list.get(i)); } else { throw new Exception("参数类型错误,请检查!"); } } } else { String sqlID = list.get(0).toString();//传入的第一个参数为SQL的ID if (list.size() == 1)//无参查询 { cro = this.ExcuteNoParameter(dao, sqlID); } else//带参查询 { cro = this.ExcuteWithParameter(dao, sqlID, list); } } } catch (Exception ex) { System.out.print("保存操作参数错误: " + ex.getMessage()); } return cro; } /** * @param sqlID * @param list * @return * @throws SQLException * @desc 带参数SQL */ private CoreReturnObject ExcuteWithParameter(String dao, 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(dao).ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID), obj); return cro; } /** * @param sqlID * @return * @throws SQLException * @desc 无参数 */ private CoreReturnObject ExcuteNoParameter(String dao, String sqlID) throws SQLException { CoreReturnObject cro = null; cro = this.getDao(dao).ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID)); return cro; } }