Java Reference
In-Depth Information
}
ps = conn.prepareStatement(sql.toString());
Iterator valueListIt =
valueList.iterator();
int indexCount = 1;
while(valueListIt.hasNext()) {
ps.setObject(indexCount,valueListIt.next());
indexCount++;
}
rs = ps.executeQuery();
while(rs.next()) {
Category category = new Category();
category.setCategoryId(rs.getInt("categoryId"));
category.setTitle(rs.getString("title"));
category.setDescription(rs.getString("description"));
category.setParentCategoryId(
rs.getInt("parentCategoryId"));
category.setSequence(rs.getInt("sequence"));
retVal.add(category);
}
} catch (SQLException ex) {
logger.error(ex.getMessage(), ex.fillInStackTrace());
} finally {
if (rs != null)
try { rs.close(); }
catch (SQLException ex)
{logger.error(ex.getMessage(), ex.fillInStackTrace());}
if (ps != null)
try { ps.close(); }
catch (SQLException ex)
{logger.error(ex.getMessage(), ex.fillInStackTrace());}
if (conn != null)
try { conn.close(); }
catch (SQLException ex)
{logger.error(ex.getMessage(), ex.fillInStackTrace());}
}
return retVal;
}
}
Prepares statement
and sets parameters
Runs the query
Iterates through results and
builds objects to return
The joy of resource cleanup
Search WWH ::




Custom Search