c00759538ec1f6fbca7106636eeb300df5b2434b.svn-base 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package UIB.COM;
  2. import java.sql.SQLException;
  3. import java.util.ArrayList;
  4. import CoreFS.SA01.CoreIComponent;
  5. import CoreFS.SA06.CoreReturnObject;
  6. /**
  7. *
  8. * @desc 增、删、改
  9. * @author meiguiping
  10. * @date 2010 4:55:31 PM
  11. */
  12. public class ComDBSave extends CoreIComponent
  13. {
  14. /**
  15. * @param list
  16. * 用1、 按照SQLID、其它参数顺序放入前台list
  17. * 用2、在ArrayList中加入ArrayList,后者与1相同,可一次执行多条SQL
  18. * @return
  19. * @throws Exception
  20. */
  21. public CoreReturnObject doXmlSave(ArrayList list) throws Exception
  22. {
  23. CoreReturnObject cro = new CoreReturnObject();
  24. if(list == null) throw new Exception("错误,参数不允许为null!");
  25. if(list.size() == 0) throw new Exception("错误,没有传入任何参数!");
  26. if(list.get(0) instanceof ArrayList )
  27. {
  28. int len = list.size();
  29. for(int i = 0; i < len ; i++)
  30. {
  31. if(list.get(0) instanceof ArrayList)
  32. {
  33. doXmlSave((ArrayList)list.get(i));
  34. }
  35. else
  36. {
  37. throw new Exception("参数类型错误,请检查!");
  38. }
  39. }
  40. }
  41. else
  42. {
  43. String sqlID = list.get(0).toString();//传入的第一个参数为SQL的ID
  44. if(list.size() == 1)//无参查询
  45. {
  46. cro = this.ExcuteNoParameter(sqlID);
  47. }
  48. else//带参查询
  49. {
  50. cro = this.ExcuteWithParameter(sqlID, list);
  51. }
  52. }
  53. return cro;
  54. }
  55. /**
  56. * @desc 带参数SQL
  57. * @param sqlID
  58. * @param list
  59. * @return
  60. * @throws SQLException
  61. */
  62. private CoreReturnObject ExcuteWithParameter(String sqlID , ArrayList list)throws SQLException
  63. {
  64. CoreReturnObject cro = null;
  65. int len = list.size()-1;
  66. Object[] obj = new Object[len];
  67. //System.out.println("list长度:"+list.size());
  68. for(int i = 0; i < len; i++)
  69. {
  70. obj[i] = list.get(i+1).toString();//第0个参数为SQL语句,SQL语句中的参数需要从第一个开始
  71. }
  72. cro = this.getDao("KgDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID) , obj);
  73. return cro;
  74. }
  75. /**
  76. * @desc 无参数
  77. * @param sqlID
  78. * @return
  79. * @throws SQLException
  80. */
  81. private CoreReturnObject ExcuteNoParameter(String sqlID)throws SQLException
  82. {
  83. CoreReturnObject cro = null;
  84. cro = this.getDao("KgDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(sqlID));
  85. return cro;
  86. }
  87. }