Problem when creating query from Java

0

Yes, look at it I have it in the following way:

public void borrarPersona(String dni) {
        Connection c = null;
        PreparedStatement preparedStatement = null;

        //Usando consultas preparadas, más seguras y más rápidas
        String insertSQL = "DELETE "
                + "FROM personas"
                + "WHERE dni LIKE ?";

        try {
            c = iniciarConnection();
            preparedStatement = (PreparedStatement) iniciarConnection().prepareStatement(insertSQL);

            preparedStatement.setString(1, dni);
            preparedStatement.executeUpdate();
            System.out.println("Registro con dni:"+dni+" ha sido borrado");

        } catch (Exception e) {
        }
    }

The System.out.println never comes out, I have also checked it in the database but it does not come out

    
asked by Selito95 28.06.2017 в 14:56
source

1 answer

0

Just add the following line: preparedStatement.setString (1, dni); before executeUpdate ()

public void borrarPersona(String dni) {
    Connection c = null;
    PreparedStatement preparedStatement = null;

    //Usando consultas preparadas, más seguras y más rápidas
    String insertSQL = "DELETE "
            + "FROM personas"
            + "WHERE dni = ?";       

    try {
        c = iniciarConnection();
        preparedStatement = (PreparedStatement) iniciarConnection().prepareStatement(insertSQL);

        preparedStatement.setString(1,dni);
        preparedStatement.executeUpdate();


    } catch (Exception e) {
    }
}
    
answered by 28.06.2017 в 15:22