b4c4a6f3ee2a63638a0e568a5520734f54845fb6.svn-base 2.6 KB

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