Im using apache derby databse in a Javafx project. Its a library management system and there's a limit to the number of books that can be added to the system.
Is there a way to limit the entries at around, let's say, a 100 books? To display an error message once that number of books have been added to the table?
I'm just gonna share my addbook method here;
<pre>public static boolean insertNewBook(Book book) {
try {
PreparedStatement statement = DatabaseHandler.getInstance().getConnection().prepareStatement(
"INSERT INTO BOOK(id,title,author,publisher,isAvail) VALUES(?,?,?,?,?)");
statement.setString(1, book.getId());
statement.setString(2, book.getTitle());
statement.setString(3, book.getAuthor());
statement.setString(4, book.getPublisher());
statement.setBoolean(5, book.getAvailability());
return statement.executeUpdate() > 0;
} catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
}
return false;
}
What I have tried:
I am not very fluent on databases and the syntax so I'm quite lost at the moment