I have a GUI system that is connected to the derby database. I want to check whether a user has taken any two books if so an error message comes up saying cannot borrow any more books anything less than that is okay.
Actually, a common way to check is to simply attempt to try and add the record and catch the Exception if it fails. Unless people are doing a lot of duplicates, it's less overhead than reading, then writing.
For such a mechanism to work, however, at least one column in the table has to have been defined as UNIQUE. If you've defined a PRIMARY KEY column, that will be the case, as PRIMARY KEYs are inherently unique.
Neither this solution nor Tom Moores's solution are Derby-specific. They apply to any SQL database.
Science is the process of replacing what we "know" with what is TRUE. Politics, alas, often prefers to be the opposite.