| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package QCM.COMMUNAL;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import CoreFS.SA01.CoreIComponent;
- import CoreFS.SA06.CoreReturnObject;
- import UIB.COM.XmlSqlParsersFactory;
- /**
- *
- * @desc 简单查询
- * @author meiguiping
- * @date 2010 8:12:02 PM
- */
- public class ComDBQueryQCM extends CoreIComponent
- {
- /**
- * @desc 简单查询,自动判断是否带有参数传递
- * @param list 第一个参数为SQL的ID
- * @return
- * @throws Exception
- */
- public CoreReturnObject doSimpleQuery(ArrayList list)throws Exception
- {
- CoreReturnObject cro = null;
- if(list == null) throw new Exception("错误,参数不允许为null!");
- if(list.size() == 0) throw new Exception("错误,没有传入任何参数!");
-
- String sqlID = list.get(0).toString();//传入的第一个参数为SQL的ID
- try
- {
- if(list.size() == 1)//无参查询
- {
- cro = this.queryNoParameter(sqlID);
- }
- else//带参查询
- {
- cro = this.queryWithParameter(sqlID, list);
- }
- }
- catch(Exception ex)
- {
- throw new Exception(ex.getMessage());
- }
-
- return cro;
- }
-
- /**
- * @desc 连续查询,执行多条查询语句,一次返回结果
- * @param al
- * @return
- */
- public CoreReturnObject doContinuousQluery(ArrayList list)throws Exception
- {
- if(list == null) throw new Exception("错误,参数不允许为null!");
-
- if(list.size() == 0) throw new Exception("错误,没有传入任何参数!");
- ArrayList al = new ArrayList();
- CoreReturnObject cro1 = new CoreReturnObject();//最终结果
- for(int i = 0; i < list.size(); i++)
- {
- al.add( doSimpleQuery((ArrayList)list.get(i)).getResult() );
- }
- cro1.setResult(al);
- return cro1;
- }
- /**
- * @desc 带参数SQL
- * @param sqlID
- * @param list
- * @return
- * @throws SQLException
- */
- private CoreReturnObject queryWithParameter(String sqlID , ArrayList list)throws SQLException
- {
- CoreReturnObject cro = null;
- int len = list.size()-1;
- Object[] obj = new Object[len];
- //System.out.println("list长度:"+list.size());
- for(int i = 0; i < len; i++)
- {
- obj[i] = list.get(i+1).toString();//第0个参数为SQL语句,SQL语句中的参数需要从第一个开始
- // System.out.println("参数值:"+obj[i].toString());
- }
- cro = this.getDao("test1Dao").ExcuteQuery(XmlSqlParsersFactory.getSql(sqlID) , obj);
- return cro;
- }
-
- /**
- * @desc 无参数查询
- * @param sqlID
- * @return
- * @throws SQLException
- */
- private CoreReturnObject queryNoParameter(String sqlID)throws SQLException
- {
- CoreReturnObject cro = null;
- System.out.println(XmlSqlParsersFactory.getSql(sqlID));
- cro = this.getDao("test1Dao").ExcuteQuery(XmlSqlParsersFactory.getSql(sqlID));
- return cro;
- }
- }
|