sb.append(" select t1.* from ( select * from employee_additional_attributes where stwid in (1,2,3,4) ) ");
sb.append(" as t1 join ( select stwid, max(employee_additional_attribute_id) as employee_additional_attribute_id from employee_additional_attributes ");
sb.append(" where stwid in (?) and mis_attribute_id = (?) and start_time <= date(?) group by stwid ) ");
sb.append(" as t2 using ( stwid, employee_additional_attribute_id ); ");
List<EtsEmployeeAdditionalAttribute> costCenterList = new ArrayList<EtsEmployeeAdditionalAttribute>();
int i = 1;
conn = STWTransactionManager.get(Thread.currentThread().getId());
stmt = conn.prepareStatement(sb.toString());
stmt.setDate(i++, new java.sql.Date(date.getTime()));
I have no idea what your code is trying to achieve, but I would suggest you start by de-bugging your SQL statement (or simply print it out) so you see what SQL you are actually executing, and which columns are being returned. Take the actual SQL this program is generating and run it using your database's SQL shell to make sure it works correctly, and you'll also be able to see what columns and rows are returned. Once you are sure your SQL is correct, it will be much easier to integrate it with your Java code correctly.
Also it's usually best to avoid "SELECT * FROM..." because you don't know if your DBA has added or removed columns in the table or changed their names. Specify the columns you want to retrieve, so you can trace errors more easily at runtime e.g. the database will tell you if a specified column doesn't exist, and also so that other programmers can see what you're trying to do in your code.