Problems with the preparedStatement

0

Thanks for your attention I would like to ask what the problem is in my code, I am doing a query with Java but when going to the preparedStatement it tells me that the connection is closed and can not execute any more operations (MySQLNonTransientConnectionException: No operations allowed after connection closed .), in the DAO class I have a constructor that has the connection.

This is the instruction:

if (compraEntradaDTO.getMovilid().isEmpty()) {
            accionresult = helper.obtenerAccionResultFalla("VFCM0002");

        } else {

            BA506_DispositivosUsuarioDAO dispositivosDAO = new 
BA506_DispositivosUsuarioDAO(ds.obtenerConexion());
            List<BA506_DispositivosUsuarioDTO> dispositivos;
            dispositivos = 
dispositivosDAO.selectXidPhone(usuarioDTO.getBA505Id(), 
compraEntradaDTO.getMovilid());

            if (dispositivos.get(0).getBA506Pho() != 
compraEntradaDTO.getMovilid()) {
                accionresult = helper.obtenerAccionResultFalla("VFCM0002");
            }

        }

And this is the query:

public List<BA506_DispositivosUsuarioDTO> selectXidPhone(int id, String 
phone) throws Exception {

    List<BA506_DispositivosUsuarioDTO> l_resultado = null;

    String sql = "SELECT " + SelectAll();
    sql += " FROM " + TABLA;
    sql += " WHERE BA506Id = ? ";
    sql += " AND BA506Pho = ?";

    PreparedStatement preparedStatemtent = conexion.prepareStatement(sql);
    preparedStatemtent.setInt(1, id);
    preparedStatemtent.setString(2, phone);

    ResultSet rs = preparedStatemtent.executeQuery(sql);
    while (rs.next()) {
        BA506_DispositivosUsuarioDTO dispositivo = getSelectFull(rs);
        l_resultado.add(dispositivo);
    }

    return l_resultado;

}

}

Obviously I used the connection in previous operations to this piece of code to different classes but I have not presented a problem, I can comment on the if and the program runs its course. I could not find the root of the problem. Thanks.

    
asked by Julian Florez 05.06.2018 в 19:04
source

1 answer

0

Remove the sql from the preparedStatemtent:

PreparedStatement preparedStatemtent = conexion.prepareStatement(sql);

And put it like this:

PreparedStatement preparedStatemtent = conexion.prepareStatement();

You already tell me!

    
answered by 05.06.2018 в 20:07