0

I have a class View with a JTable and another class DB. In DB is a method with a database connection. When calling this method from View, I want it to return the whole data from the database. What exactly should I use as the return type? List, Vector, Array, Map,...?

I read lots of tutorials, but got very confused of the various possibilities. I really nead the easiest way, just to understand how it works.

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181
  • 1
    *"What exactly should I use as the return type?"* The [`ResultSet`](http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html) would be my 1st choice. – Andrew Thompson Jan 08 '12 at 03:17
  • duplicated at http://stackoverflow.com/questions/8774481/filling-object-data/8774505 and http://stackoverflow.com/questions/8751735/java-retrieving-data-from-database-and-load-in-jtable – alf Jan 08 '12 at 11:06

2 Answers2

5

The return type should be whatever you want your TableModel to support.

See Table From Database for some ideas.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • The problem is, I don't know what I want. I have just plain text and Integers in my database. Is there something like a "comparisson" of those types to choose the right one? – Evgenij Reznik Jan 08 '12 at 19:13
  • As Bill has already noted below, the simplest is the DefaultTableMdoel if you don't know what you want. Then as you become more experienced with using TableModels you can start to create custom and reusable models. – camickr Jan 08 '12 at 20:00
0

The easiest way is to put your data in vectors, and then construct a Vector from the data, and then construct a DefaultTableModel with that data.

If all you need to do is view the data this is the easiest way. Its not really a good way for viewing the data though, and its really quite bad when it comes to editing.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57