what is the value of resultset ,if query does not return any record?
public Resul开发者_Go百科tObject 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;
}
this is the code
According to the javadoc, Statement.executeQuery()
never returns null
. So the answer is a ResultSet
with no rows.
You can tell that the ResultSet is empty if next()
returns false
the first time you call it.
You may also be able to tell by calling the optional isAfterLast()
method. If it is supported, this method will give you an answer without advancing the cursor as a side-effect.
I've no idea what the answer would be for your code, since you are calling an execute
method whose implementation you have not provided.
ResultSet executeQuery(String sql) throws SQLException Executes the given SQL statement, which returns a single ResultSet object.
Parameters: sql - an SQL statement to be sent to the database, typically a static SQL SELECT statement
Returns: a ResultSet object that contains the data produced by the given query; never null
Throws: SQLException - if a database access error occurs, this method is called on a closed Statement or the given SQL statement produces anything other than a single ResultSet object
- Statement
Also you can do it like:
if(resSet.last().getRow() > 0)
{
resSet.first();
while(resSet.next())
{
colValidRecord.add(resSet.getString("DESTINATIONGROUPID"));
}
}
else
{
//...
精彩评论