Syntax error Mysql in J2EE Web application Servlets and JSP's

1

I am building a small web app using NetBeans 8.2 with J2EE.

At the moment of executing the following query in the DAO, it shows me a MySQL syntax error that does not exist since if I execute the query in the BD manager there is no syntax problem and the query runs without problems. Then my code:

public Registro consultar(String placa) throws SQLException {
    String consulta = "select registro.id_registro, registro.horaInicio, registro.horaFin, registro.valorApagar, registro.id_cliente, registro.id_espacio, registro.placa, registro.tipo from registro inner join vehiculo on (registro.placa=vehiculo.placa) where vehiculo.placa=?;";
    PreparedStatement statement = this.conexion.prepareStatement(consulta);

    statement.setString(1, placa);

    ResultSet resultado = statement.executeQuery(consulta);

    while (resultado.next()) {
        TipoEspacio tipoEspacio = new TipoEspacio();
        tipoEspacio.setTipoEspacio(resultado.getString("id_espacio"));

        Espacio e = new Espacio();
        e.setNumeroEspacio(resultado.getInt("id_espacio"));
        e.setTipo(tipoEspacio);

        TipoVehiculo tipoVehiculo = new TipoVehiculo();
        tipoVehiculo.setTipo(resultado.getString("tipo"));
        Vehiculo vehiculo = new Vehiculo();
        vehiculo.setPlaca(placa);
        vehiculo.setTipoVehiculo(tipoVehiculo);

        Registro registro = new Registro();
        registro.setEspacio(e);
        registro.setVehiculo(vehiculo);
        java.util.Date horaFin = new java.util.Date();
        registro.setHoraFin(horaFin);
        return registro;

    }
    return null;
}

The error that Glassfish shows:

  

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

I hope you can help me.

Thanks

    
asked by Jose Paredes 23.10.2017 в 13:40
source

1 answer

3

Your error is because you are calling executeQuery with a parameter that is not necessary. Call it without parameters:

ResultSet resultado = statement.executeQuery();
    
answered by 23.10.2017 / 15:20
source