2010-12-09 78 views
-1
public ResultObject takePrefixGroupId(ArrayList prefixGroupName) 
{ 
debugLog(MODULE_NAME, "Inside the takePrefixGroupId() of LCRConfigurationSessionBean"); 
ResultObject resultObject = new ResultObject(LCRResponseCode.LCR_CONFIGURE_SEARCH_ERROR_EJB, null); 

String strSelectQuery = null; 
String strMessage=null; 
ResultSet resSet = null; 
Collection colInValideRecord =new ArrayList(); 
Collection colErrorMessage=new ArrayList(); 
Collection colValidRecord = new ArrayList(); 
Collection colDataValidation=null; 
try{ 
    for(int i=0;i<prefixGroupName.size();i++) 
    { 
    strSelectQuery = "select DESTINATIONGROUPID from TBLMDESTINATIONGROUP where NAME='"+prefixGroupName.get(i)+"'"; 
    debugLog(MODULE_NAME, "Query::::::"+strSelectQuery); 
    resultObject = execute(strSelectQuery); 
    if(resultObject.getResponseCode() == LCRResponseCode.SUCCESS_RESPONSE_CODE) 
    { 
    resSet = (ResultSet)resultObject.getResponseObject(); 
    debugLog(MODULE_NAME, "resSet::::::"+resSet); 
    if(resSet != null) 
    { 
    while(resSet.next()) 
    { 
     colValidRecord.add(resSet.getString("DESTINATIONGROUPID")); 
    } 
    } 
    else 
    { 
    strMessage=LCRResponseCode.errorCodeToMessage(LCRResponseCode.PREFIX_GROUP_DOES_NOT_EXIST_ERROR); 
    debugLog(MODULE_NAME,"MESSAGE::: "+strMessage); 
    colErrorMessage.add(strMessage); 
    colInValideRecord.add(prefixGroupName); 
    debugLog(MODULE_NAME,"No Prefix Group is found."); 
    } 
    colDataValidation=new ArrayList(); 
    colDataValidation.add(colValidRecord); 
    colDataValidation.add(colInValideRecord); 
    colDataValidation.add(colErrorMessage); 
    resultObject.setResponseObject(colDataValidation);  
    resultObject.setResponseCode(LCRResponseCode.SUCCESS_RESPONSE_CODE); 

    } 
    else 
    { 
    debugLog(MODULE_NAME, "Unable to execute search query for in searchDestination() of LCRConfigurationSessionBean."); 
    resultObject.setResponseCode(LCRResponseCode.LCR_CONFIGURE_SEARCH_ERROR_EJB); 
    } 
    } 

} 
catch(Exception e) 
{ 
    e.printStackTrace(); 
    errorLog(MODULE_NAME, "exception in searchDestination() of LCRConfigurationSessionBean"); 
    resultObject.setResponseCode(LCRResponseCode.LCR_CONFIGURE_SEARCH_ERROR_EJB); 
    resultObject.setException(e); 
} 
return resultObject; 
} 

這是代碼如果查詢沒有返回任何記錄,結果集的值是多少?

+0

如果您想要答案,則必須重新格式化您的代碼。格式化幫助,請訪問http://stackoverflow.com/editing-help – Jason 2010-12-09 06:15:02

+0

@Jason:完成:) – Asaph 2010-12-09 06:16:13

回答

6

the javadocStatement.executeQuery()永遠不會返回null。所以答案是沒有行的ResultSet

如果第一次調用next()時返回false,那麼可以知道ResultSet爲空。

您也可以通過調用可選的isAfterLast()方法來判斷。如果支持,該方法將給你一個答案,而不會將光標作爲副作用前進。


我不知道是什麼,答案將是你的代碼,因爲你調用一個方法execute其實現您沒有提供。

0

結果集的executeQuery(字符串SQL) 拋出的SQLException執行給定的SQL語句 ,其返回單個 ResultSet對象。

參數: SQL - SQL語句發送到數據庫中,通常 靜態SQL SELECT語句

返回:包含由 定查詢所生成數據的ResultSet對象;不能爲null

拋出: SQLException - 如果發生數據庫訪問錯誤,這 方法被調用關閉的Statement 或者給定的SQL語句生成其他 任何單個ResultSet 對象

你也可以做到這一點,如:

if(resSet.last().getRow() > 0) 
{ 
resSet.first(); 
while(resSet.next()) 
{ 
    colValidRecord.add(resSet.getString("DESTINATIONGROUPID")); 
} 
} 
else 
{ 
//...