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?
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.
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).
Joined: Jan 06, 2010
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.