0

I'm trying to come up with a way to transfer data from a Database to a JTable, At first i was thinking to do it using a ResultSet into a Vector into a DefaultTableModel, because DefaultTableModel takes only a Vector, But later as i read it seems that vector is obsolete and deprecated. So my question is, Would it be bad programming to use Vector in such case? And if vector is deprecated then why does DefaultTableModel takes only a Vector?

-thanks.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Dani Gilboa
  • 599
  • 4
  • 13
  • 30
  • Who says that vector is deprecated? As of Java 7 it is not. Anyway, the bad idea here is tying the GUI and persistence layers (that is, passing the data directly in the ResultSet instead of in an agnostic object -v.g. a bean-). – SJuan76 Sep 21 '13 at 12:52
  • @SJuan76 not flamewar, my view beans caused another issues, important is performance for me – mKorbel Sep 21 '13 at 12:56

2 Answers2

1

And if vector is deprecated then why does DefaultTableModel takes only a Vector?

  • DefaultTableModel takes simple array Object, String, Integer, Boolean[] in JTablel or for DefaultTableModel too

  • Vector is still and will be Contructor for JTable, DefaultTableModel (pre_realeses for Java8 haven't any changes)

  • DefaultTableModel provide simple implementations for all methods required for JTable, everything moreover is only about restriction or enhancements methods implemented in DefaultTableModels API

  • you can to use util.List as underlaying array for JTable, better alternative to Vector but then I suggest to use AbstractTableModel,

  • in AbstractTableModel you can to use Object, String, Integer, Boolean[] or Vector> as underlaying arra too

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • there are optimized classes for JDBC_to_JTable, by default based on AbstractTableModel, (Vector or util.List) search for ResultSetTableModel or TableFromDatabase for more info, and to avoid reinvent the wheel – mKorbel Sep 21 '13 at 13:00
1

I read that vector is obsolete and collections should be used instead ,

A Vector is part of the Collections framework. It implements the List interface the same as an ArrayList does. The difference is that Vector is automatically synchronized and ArrayList is not. This will make little difference (if any) when using a JTable in a gui.

If you want a model that does use an ArrayList then you can check out List Table Model. Also, see Table From Database for an easy way to use a ResultSet to create the ListTableModel.

camickr
  • 321,443
  • 19
  • 166
  • 288