Problem with SQLite query (Unanticipated Result)

1

Good I want to make a delete using SQLite and I would like the query not to run if the field of the where did not exist, is this possible? Then I leave an example of my query:

delete from SANCION_DETALLE where SANCION_DETALLE.SANCION = 47

(This query is executed even though there is no sanction 47 on my table)

Thanks in advance.

    
asked by Dejuanfran99 07.11.2018 в 20:36
source

1 answer

1

If you're working in Java, try saving the records you find in an array, and then put in the WHERE condition only the elements of that array. Try this:

ArrayList<String> registrosEliminados = new ArrayList<>();
StringBuilder query = new StringBuilder();
              query.append("DELETE FROM detalle ");
              query.append("WHERE sancion like '" + sancion + "';");

Statement st = conexion.createStatement();
if(st.executeUpdate(this.query.toString()) == 0) {
     System.out.println("---Sanción no existe o ha sido borrada---");
}else {
     this.registrosEliminados.add(sancion);
}
    
answered by 08.11.2018 / 08:27
source