java – Limit a SQL record


Is it possible to make a registry use restricted after certain uses? The thing is that I am making a program that is based on a library database and I want the endorsement to be used a maximum of 5 times.

Here is the part of the user registration code:

    Connection net=DriverManager.getConnection("jdbc:mysql://localhost:3306/Biblioteca?&useSSL=false", "root", "");
    Statement stmt=net.createStatement();
    stmt.executeUpdate("INSERT INTO Clientes(Id, Nombre, Apellidos, Ocupación, Dirección, Correo, Teléfono, Identificación, `Nombre Aval`, `Apellidos Aval`) Values(NULL,'"+textField.getText()+"','"+textField_1.getText()+"','"+textField_2.getText()+"','"+textField_3.getText()+"','"+textField_4.getText()+"','"+textField_5.getText()+"','"+textField_13.getText()+"','"+textField_6.getText()+"','"+textField_7.getText()+"')");
    stmt.executeUpdate("INSERT INTO Aval(Id, Nombre, Apellidos, Dirección, Correo, Teléfono, Ocupación, Parentesco, Identificación) Values(NULL,'"+textField_6.getText()+"','"+textField_7.getText()+"','"+textField_8.getText()+"','"+textField_9.getText()+"',"+textField_10.getText()+",'"+textField_11.getText()+"','"+textField_12.getText()+"','"+textField_14.getText()+"')");
    stmt.executeUpdate("UPDATE Aval SET Usos=Usos+1 WHERE Nombre='"+textField_6.getText()+"' AND Apellido='"+textField_7.getText()+"'");
    textPane.setText("Registro exitoso.");
}catch(Exception ex){


You have to control the records with a State and verify said state and the business rules (in this case that it is not "used" more than 5 times) before using it. You must do it from the database manager side because if the business rules change you will have to modify your source code having to compile and publish again.

Scroll to Top