2fc700dea0ed0acfdcb65895724dd9c15c32f6d5.svn-base 2.8 KB

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