I have a problem, I have no idea how to solve it.
I am running GROUP_CONCAT
for a pivot table in MySQL and running by PREPARED STATEMENT
. So far so good, now when I try to recover result set
I can only recover fixed values for example, string or integers without operations.
I need to add a simple sum operation with integers, which is not possible because the returned values are null.
In this case, I can only retrieve the information of NameSchool, values manipulated (CAST((REPROVADO)/(APROVADO+REPROVADO) AS SIGNED))
return null
.
@SQL:
SELECT nomeEscola,
MAX(IF(temp_graph2.anoBase = '2012', CAST((REPROVADO)/(APROVADO+REPROVADO) AS SIGNED), NULL)) AS '2012',
MAX(IF(temp_graph2.anoBase = '2014', CAST((REPROVADO)/(APROVADO+REPROVADO) AS SIGNED), NULL)) AS '2014',
MAX(IF(temp_graph2.anoBase = '2013', CAST((REPROVADO)/(APROVADO+REPROVADO) AS SIGNED), NULL)) AS '2013'
FROM temp_graph2
GROUP BY nomeEscola
ResultSet MYSQL:
nomeEscola 2012 2014 2013
xxxxx 0,027 {null} {null}
xxxxx {null} 0,109 {null}
xxxxx {null} {null} 0,333
xxxxx {null} {null} 0,222
xxxxx {null} {null} {null}
xxxxx {null} {null} 0,083
xxxxx {null} {null} {null}
xxxxx {null} {null} 0,3
Recuperando o ResultSet:
final StringBuffer query = new StringBuffer("PREPARE stmt FROM @sql;");
pStmt = conn.prepareStatement(query11.toString());
pStmt.executeUpdate();
final StringBuffer query2 = new StringBuffer("EXECUTE stmt;");
pStmt = conn.prepareStatement(query2.toString());
rstSet = obterResultadoDaConsulta(new Object[]{}, pStmt);
rstSet.beforeFirst();
int columns = metaData.getColumnCount();
while (rstSet.next()) {
record = new ArrayList<Object>();
for (int i = 1; i <= columns; i++) {
if(i==1){
Object value = "'"+rstSet.getObject(i).toString().replace("\"","")+"'";
record.add(value);
}else{
Object value = rstSet.getObject(i);
record.add(value);
}
}
if (!record.contains(null)){
al.add(record);
}
}