Problem to sum values in JDBC

Asked

Viewed 40 times

1

The console presents me the following error:

FUNCTION worksoviagemd.SUM does not exist. Check the 'Function Name Parsing and Resolution' Section in the Reference Manual

Can only be sql in my prepareStatement, help me!

Dao method

public List<ViagemBean> getListaTotalDiaria(String totalDiaira) {
    try {
        List<ViagemBean> viagens = new ArrayList<ViagemBean>();

        ConexaoMySQL.conectar();

        PreparedStatement stmt = ConexaoMySQL.getConexao()
                .prepareStatement("select SUM (valorDiaria) as total from viagem where colaborador = ? ");

        stmt.setString(1, totalDiaira);  

        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            // criando o objeto viagem
            ViagemBean viagem = new ViagemBean();

            viagem.setValorDiaria(rs.getDouble("total"));

            // adicionando o objeto à lista
            viagens.add(viagem);
        }
        rs.close();
        stmt.close();
        return viagens;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

1 answer

1


You left a space between the function and the parameter.

select SUM (valorDiaria) 

Arrange for:

select SUM(valorDiaria) 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.