0845627192237cd763c8f59c4257a1ab4b0ab5e8.svn-base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package QCM.COMMUNAL;
  2. import java.sql.SQLException;
  3. import java.util.ArrayList;
  4. import CoreFS.SA01.CoreIComponent;
  5. import CoreFS.SA06.CoreReturnObject;
  6. import UIB.COM.XmlSqlParsersFactory;
  7. /**
  8. *
  9. * @desc 简单查询
  10. * @author meiguiping
  11. * @date 2010 8:12:02 PM
  12. */
  13. public class ComDBQueryQCM extends CoreIComponent
  14. {
  15. /**
  16. * @desc 简单查询,自动判断是否带有参数传递
  17. * @param list 第一个参数为SQL的ID
  18. * @return
  19. * @throws Exception
  20. */
  21. public CoreReturnObject doSimpleQuery(ArrayList list)throws Exception
  22. {
  23. CoreReturnObject cro = null;
  24. if(list == null) throw new Exception("错误,参数不允许为null!");
  25. if(list.size() == 0) throw new Exception("错误,没有传入任何参数!");
  26. String sqlID = list.get(0).toString();//传入的第一个参数为SQL的ID
  27. try
  28. {
  29. if(list.size() == 1)//无参查询
  30. {
  31. cro = this.queryNoParameter(sqlID);
  32. }
  33. else//带参查询
  34. {
  35. cro = this.queryWithParameter(sqlID, list);
  36. }
  37. }
  38. catch(Exception ex)
  39. {
  40. throw new Exception(ex.getMessage());
  41. }
  42. return cro;
  43. }
  44. /**
  45. * @desc 连续查询,执行多条查询语句,一次返回结果
  46. * @param al
  47. * @return
  48. */
  49. public CoreReturnObject doContinuousQluery(ArrayList list)throws Exception
  50. {
  51. if(list == null) throw new Exception("错误,参数不允许为null!");
  52. if(list.size() == 0) throw new Exception("错误,没有传入任何参数!");
  53. ArrayList al = new ArrayList();
  54. CoreReturnObject cro1 = new CoreReturnObject();//最终结果
  55. for(int i = 0; i < list.size(); i++)
  56. {
  57. al.add( doSimpleQuery((ArrayList)list.get(i)).getResult() );
  58. }
  59. cro1.setResult(al);
  60. return cro1;
  61. }
  62. /**
  63. * @desc 带参数SQL
  64. * @param sqlID
  65. * @param list
  66. * @return
  67. * @throws SQLException
  68. */
  69. private CoreReturnObject queryWithParameter(String sqlID , ArrayList list)throws SQLException
  70. {
  71. CoreReturnObject cro = null;
  72. int len = list.size()-1;
  73. Object[] obj = new Object[len];
  74. //System.out.println("list长度:"+list.size());
  75. for(int i = 0; i < len; i++)
  76. {
  77. obj[i] = list.get(i+1).toString();//第0个参数为SQL语句,SQL语句中的参数需要从第一个开始
  78. // System.out.println("参数值:"+obj[i].toString());
  79. }
  80. cro = this.getDao("test1Dao").ExcuteQuery(XmlSqlParsersFactory.getSql(sqlID) , obj);
  81. return cro;
  82. }
  83. /**
  84. * @desc 无参数查询
  85. * @param sqlID
  86. * @return
  87. * @throws SQLException
  88. */
  89. private CoreReturnObject queryNoParameter(String sqlID)throws SQLException
  90. {
  91. CoreReturnObject cro = null;
  92. System.out.println(XmlSqlParsersFactory.getSql(sqlID));
  93. cro = this.getDao("test1Dao").ExcuteQuery(XmlSqlParsersFactory.getSql(sqlID));
  94. return cro;
  95. }
  96. }