File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should I use objects or not???

 
Andrew Robinson
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 47281
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic