| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package UIB.COM;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import CoreFS.SA01.CoreIComponent;
- import CoreFS.SA06.CoreReturnObject;
- /**
- *
- * @desc 增、删、改
- * @author meiguiping
- * @date 2010 4:55:31 PM
- */
- public class ComDBSave extends CoreIComponent
- {
- /**
- * @param list
- * 用1、 按照SQLID、其它参数顺序放入前台list
- * 用2、在ArrayList中加入ArrayList,后者与1相同,可一次执行多条SQL
- * @return
- * @throws Exception
- */
- public CoreReturnObject doXmlSave(ArrayList list) throws Exception
- {
- CoreReturnObject cro = new CoreReturnObject();
- 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)
- {
- doXmlSave((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);
- }
- }
- 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("KgDao").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("KgDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID));
- return cro;
- }
- }
|