ArrayList queryParms = new ArrayList();
StringBuffer sql = new StringBuffer();
sql.append(
"SELECT A.FLDREC_NUM, " +
"@CHARDATE(A.FLDDATE), " +
"T.FLDDESCR, @DEC(A.FLDLEVEL,3) " +
" FROM @SCHEMAALCOHOL A LEFT OUTER JOIN @SCHEMADRUGCAUS T " +
" ON A.FLDREASON = T.FLDCODE " +
" WHERE A.FLDEMPLOYEE = ? " +
" ORDER BY A.FLDDATE DESC"
);
queryParms.add(new Long(empRec));
-
Can i use HashSet instead of ArrayList above and does it make any sense in terms of performance?.
-
What does the query do, do we need to append the query in StringBuffer. Why can’t i directly add to ArrayList?
In general, you would want to use an
ArrayListfor query parameters – because the order matters. When you’ve only got a single parameter (as you have here) it’s not an issue – but I’d definitely use a list for consistency.As for using
StringBuffer– you haven’t shown what you’re doing withsqlhere. If you’re not appending anything else, you could use a simpleString… but you wouldn’t be adding it to theArrayList, as it’s the query itself, not a query parameter.Finally, I’d recommend using generics, e.g.