955a846da50ce7523b80856b7e4b24a4c88a6071.svn-base 2.5 KB

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