Help: Java Project using Databases

Soldato
Joined
5 Dec 2003
Posts
2,716
Location
Glasgow
Hey I've got this Java project for Uni to do, it's a DVD rental system. Basically looking through my notes is getting me nowhere, it appears I have half a dozen half-completed examples of how to use databases in various ways - there is Access, Oracle, JDBC, HSQLDB and DB4O, just wondering if anyone can give me some guidance on what is the easiest method for me to choose to do my project using Netbeans? (Oracle obviously isn't an option as don't have it on the home PC) Then I can research that myself and figure out how to use it as my lecture notes are diabolical.

Also, getting a step ahead of myself, I really am struggling to visualise how I am going to use the database, I mean I have my class diagram with a customers class where they will put in their details and a DVD class for adding or removing DVDs and that will go into its own DB table I guess but I don't know the best way to say a DVD is rented or returned/in stock or whatever, does anyone have any ideas on this? I guess some kind of orders table with a unique ID? But what if I have a number of the same DVD? And do I need to transfer DB rows from the DVD table to the customer table and back? Just seems to confuse me more I think about it.
 
Easiest way to do it is to use Java Persistence API and Hibernate framework. You could hack something together without but it wont be anywhere near as good.
 
Hi,

One thing you should bear in mind are that the database tables and classes that you use in your app probably won't (shouldn't?) be a like-for-like mapping. The link between the Object-Oriented classes and the Relational database structure isn't always the easiest. The database holds data so that it can be accessed and manipulated in the most efficient way. The classes your app uses model the data in the most relevant way to the problem being solved.

For example, your DVD class will have a method to populate itself with details for a particular DVD (possibly via a constructor). This method will use SQL bringing together data from a number of different tables. Similarly, your Customer class will have a method for hiring a DVD that will update a number of tables.

The database and objects shouldn't be closely related to each other. It could well be that there are a number of applications using the same database but in different ways. These applications will likely have different classes. If you let the class design for an app affect the structure of the database tables you'll reduce the reuseability of the database.

Personally I'd design the database first so it holds the required data. Then design the application that's going to use the data.

I think the NetBeans IDE has a database installed with it. Not too sure how easy that is to use though. Another alternative would be MySQL. You could access this using JDBC, creating Java classes that will perform all your SQL. There's plenty of stuff about connecting MySQL to Java via JDBC on the Internet. JDBC isn't the best, but it is relatively easy once you've written your DB handling classes.

In order to record each DVD I'd give each DVD a unique ID. Each DVD would also have a titleid (for want of a better term) that would link it back to a table giving the name, actors etc. So, if I had four copies of Star Wars they might have unique ids of 1,2,3,4 but would all have the same titleid. This arrangement enables each DVD in the system to be handled by itself but also handled as one of a group of like-titled DVDs.

Recording the rental of a DVD can then be done by inserting a row onto a "hire" table for the unique ID, giving the supposed return date, customer who rented it etc.

Hope some of that helps and there's not too much waffle in there.

Jim
 
Easiest way to do it is to use Java Persistence API and Hibernate framework. You could hack something together without but it wont be anywhere near as good.

Yup. Id echo this 100%. Using the persistence framework will also help make your app more database agnostic.
 
Back
Top Bottom