1

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?

2

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

So, in Java don't exists a mechanism like .net databinding. Something like: mytable.datasource = myds ; mytable.datamember = my-table-name ?
Not that familiar with .net databinding, there might be a third party library that could do that, but it looks scary.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.