Take the 2-minute tour ×

I'm a .net developer that would like to try develop some simple apps in Java. I would like to know how to do databinding in Java.

How can I show a query result in a JTable?

share|improve this question
you can check here download.oracle.com/javase/tutorial/uiswing/components/… –  GustyWind Jun 20 '11 at 9:12
Then (after reading GustlyWind suggestion), you should definitly take a look a GlazedLists library (glazedlists.com), that will help a lot in JTable usage. –  jfpoilpret Jun 20 '11 at 14:02
add comment

1 Answer

up vote 4 down vote accepted

GustlyWind's comment is the best place to look on how to use a JTable. The key for the data is getting the items in a model. You can use the DefaultTableModel which would require that your table results are put into a 2D Array or Vector. Or you could implement your own model that uses other custom objects from your application or a different underlying data structure.

Either way, as you loop through the ResultSet of your query you are going to have to pull the relevant data and stick it in some sort of Collection.

share|improve this answer
So, in Java don't exists a mechanism like .net databinding. Something like: mytable.datasource = myds ; mytable.datamember = my-table-name ? –  stighy Jun 20 '11 at 12:27
Not that familiar with .net databinding, there might be a third party library that could do that, but it looks scary. –  jzd Jun 20 '11 at 12:45
In my experience (indirect only, I have supervised a team using it), .NET data-binding is a nightmare for applications with a complex UI, it almost always leads to spaghetti code that nobody can maintain. –  jfpoilpret Jun 20 '11 at 14:04
add comment

Your Answer


