I am used to programming java on the server side with ORM frameworks and using abstract classes for CRUD. But now I'm workign on a desktop project without ORM and just the good old JDBC API for database interaction (And I can't).

I thought to implement an AbstractDaoCrud to encapsulate basic CRUD operations, but I guess it is a little useless since I have to implement all the CRUD methods if I want to use it.

What should be the best design be to abstract the database layer in a desktop project like this?

  • Hopefully I captured what you meant correctly. I edited the question for clarity. – Berin Loritsch May 9 at 20:32
  • 1
    Take a look at how Spring implements its JdbcTemplates. IMO that's, at best, the max abstraction you can have working with JDBC. Or take a look at myBatis, it goes a little bit further. – Laiv May 10 at 10:20

Pretend the database didn't exist. Now what do you need? Do you need things to persist when the desktop app is closed? Do you need transactional guaranties that you don't know how to code your self? Do you need relational magic?

If you can do without that stuff or solve it in some other way don't automatically reach for the database to do it. And if you do need the database to do it be very narrow and exact about what you let the database do for you. Try not to let knowledge of the particular flavor of the database creep into your app. Do this and you'll find your database has a lot of magical mumbo jumbo that you just don't care about. That's good because since your app doesn't ask for more than it needs there will be many different options to give it what it needs. You might not even need a database at all.

The real secret is making those needs clear. Do that and everything becomes simpler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.