That's the query i'm running in database:
SELECT CD_MAT, SUM(QT_MAT_UTIL) AS QT_MAT_UTIL FROM T476
WHERE (CD_UN_EXEC_SERV= 'X10' OR CD_UN_EXEC_SERV IN (SELECT
A.CD_UN_ORGANIZ FROM T016 A WHERE A.CD_UN_ORGANIZ_HIE ='X10'))
AND MM_RA_EXEC = 6 AND AA_RA_EXEC = 2016
AND CD_MAT = 15210001010
GROUP BY CD_MAT
ORDER BY 1 ASC, 2 DESC;
And that's the result I get when I run it in IBM Acess:
And that result is correct.
But when I run that same query in java using ResultSet, that's the result I get:

I have no idea why this is happening. Does anyone knows what am i doing wrong?
That's my java code(i'm absolutely sure that the variables are right):
public ArrayList<Map<String, Object>> myProblematicMethod(String cod, Integer first, Integer last) throws Excecao {
ArrayList<Map<String, Object>> lista;
lista = new ArrayList<>();
try {
StringBuffer sql = new StringBuffer();
sql.append("SELECT CD_MAT , SUM(QT_MAT_UTIL) AS QT_MAT_UTIL FROM T476 ");
sql.append(" WHERE (CD_UN_EXEC_SERV = ? OR CD_UN_EXEC_SERV ");
sql.append(" IN (SELECT A.CD_UN_ORGANIZ FROM T016 A ");
sql.append(" WHERE A.CD_UN_ORGANIZ_HIE = ?)) ");
sql.append(" AND MM_RA_EXEC= ? AND AA_RA_EXEC= ? ");
sql.append(" AND CD_MAT = 15210001010 ");
sql.append(" GROUP BY CD_MAT ORDER BY 1 ASC, 2 DESC ");
PreparedStatement ps = this.banco.criarPS(sql.toString());
ps.setString(1, cod);
ps.setString(2, cod);
ps.setInt(3, first);
ps.setInt(4, last);
ResultSet resultSet = this.banco.consultarSQL(ps);
while (resultSet.next()) {
LinkedHashMap<String, Object> materiais = new LinkedHashMap<>();
// campos presentes em todas as consultas realizadas
materiais.put("cod", resultSet.getString("CD_MAT"));
materiais.put("qnt", resultSet.getBigDecimal("QT_MAT_UTIL"));
lista.add(materiais);
}
} catch (SQLException e) {
e.printStackTrace();
throw new Excecao(e.getErrorCode(), e.getSQLState() + " - " + e.getMessage());
}
return lista;
}
Java does not return any exception to me and there's no other column with that value it is returning. I'm using java 1.8.0_65.

this.banco.criarPSis doing something, and we don't know what. I'm already a little suspicious of anything that ships a query string to something else for query preparing. Side note: As presented, there's no reason to use aStringBuffer- just create it as a singleString. Also, there's ways to use named parameters (requires more setup, though), but possibly not your actual problem.