Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic Database Class

 
david powell
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am developing an application in java which will query and update/delete from a database (I am currently using an Access database for a prototype). The problem I have got is that I have a database schema which has relations such as - 'one client to many products'. E.g - I have got a client table and a product table with the clients primary key as the foriegn key in the product table. Amyway, at present, I have got java classes to reflect this data structure - so my client class contains a vector of product objects. I am attemting to find a generic way of executing the sql statments - at the moment, I am hard coding all sql statements which is obviously no good! I want to be able to send an object to the database and have a generic method for 'insert' which will identify the correct table and update it. (has anyone out there developed a generic database access class?)I hope this makes sense but it is difficult to explain! Any help at all would be really appreciated! Thanks in advance!
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I think I understand you. The problem you describe turns out to be very difficult, but also very common. If that's the only relation you have, I would just stay with your hand-coded solution. If you have a more complex database schema, it might be time to look at third-party packages that have already solved the problem: EJB 2.0, JDO, Hibernate, TopLink, Castor, etc. I recommend starting with Hibernate, which is free, and relatively easy to use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic