Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
CHill60 2-Jan-19 8:01am    
I'm not sure of the syntax but you could try doing SELECT COUNT(*) FROM BOOK and if the number is >= 99 issue an error otherwise add the new item. It's not very sensible in a multi-user environment but there again, having a limit on the number of items in a database defeats the purpose too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900