• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

How to check whether a specific record has been entered by a User twice in Derby Database?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 6984
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I don't think there's anything Derby-specific in the question. We don't know the schema of the DB you're using, but something like this should do the trick:



assuming that "books_lent" is the table where all currently lent books are stored. The query will tell how many books the user has currently taken out.
 
Saloon Keeper
Posts: 23729
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Muhammed!

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.
 
What? What, what, what? What what tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic