File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Should I use objects or not??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Should I use objects or not???" Watch "Should I use objects or not???" New topic

Should I use objects or not???

Andrew Robinson

Joined: Jan 06, 2010
Posts: 15
I am in the process of developing an application that will be using a mysql DB. This is my first full blown application that I am designing and implementing on my own. I am curious whether it is a good design to take the information from the user (in the form of text fields) and create an object with that information. And in turn use the information to insert it into a DB. I guess what my big question is: Is it better to create objects from the data in the DB in order to make using the data easier or is it bad because it will kind of be redundant?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
Welcome to JavaRanch

Since Java is designed to handle objects, it will probably be best to take the data from the database and incorporate them into objects. Your Person table with name and date of birth and address can easily be turned into a Person object, or vice versa.
Remember some data types will be converted into objects automatically; your VARCHARs turn into Strings and your DECIMALs into BigDecimals. Also there is not always a straight one-to-one correspondence between SQL types and Java types, null being probably the worst offender in that respect.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Creating objects for rows in a table is pretty much a standard approach these days; it's how APIs like JPA and Hibernate operate. If you get to design the DB layer, start by checking out JPA and one of its implementations (like OpenJPA or Hibernate).
Andrew Robinson

Joined: Jan 06, 2010
Posts: 15
Thanks! I was thinking that it made sense to make objects, simply because of how easy it is to manipulate the data that way. I just wanted to make sure I wasn't going to run into problems with having tons of objects.

Also, does anyone know how to create a table on the fly with the rows from lets say a Person table each with like a radio button so you can select a certain "person"? I have done this in a Web app using jsp and javascript by generating HTML code, but I am not sure how to go about it using strictly java and a java GUI.
I agree. Here's the link:
subject: Should I use objects or not???
It's not a secret anymore!