I have a little problem with this code and maybe someone can help me. It happens that I have three tables, loan, item, inventory. the loan and item tables are related, but the inventory is not, the fact is that when I make a loan, I have to decrease the amount in the felling element of the "element" that I am lending, well here it works to the perfection. the question is, how do I do it for at the same time I also decrease that amount in the inventory taking into account that inventory is NOT rationed with any table?
I have this method so far ...
public boolean AgregarPrestamo(int id_persona, int id_elemento, int id_curso, int cantidad_elem_pres, String fecha_hora_prestamo, String estado_inicial) {
String consulta = "insert into prestamo values ("+null+","+id_persona+","+id_elemento+","+id_curso+","+null+","+cantidad_elem_pres+",'"+fecha_hora_prestamo+"',"+null+",'"+estado_inicial+"','"+null+"');";
String consulta1 = "update inventario set ejemplares=ejemplares-"+cantidad_elem_pres+";";
String consulta2 ="UPDATE elemento SET ejemplares=ejemplares-"+cantidad_elem_pres+" where id_elemento="+id_elemento;
System.out.println(consulta);
System.out.println(consulta1);
System.out.println(consulta2);
if (con.insertarDatos3(consulta,consulta1,consulta2)) {
con.desconectar();
return true;
} else {
con.desconectar();
return false;
}
}
The problem is that if I update the amount in the inventory table, but not the specific item, if not update the amount of all items in the inventory ...
I appreciate your help, greetings