facebook

How wire a database table to jTable (i.e. to a datamodel)

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #300770 Reply

    MikeKing
    Member

    I am using MyEclipse Professional 7.5

    I have used hibernate to reverse engineer an existing database (dao’s etc).
    I have used Matisse to create a form with a jtable in a scroll window

    What is the simplest way to use MyEclipse to wire a db table to the jTable.
    I know that I must specify a model for the jTable, but in the MyEclipse example the model is set up to contain ‘hard coded’ data, not a db table.

    I guess that one must bind the database table to a DefaultDataModel and then base the jTable on this. Must I use the DAO findAll() method? But this returns a List, not a DataModel!

    How does one do this. Will MyEclipse automate part of it?

    I am currently sitting with the database tables reverse engineered into Classes and DAOs etc, but am stuck.

    Some help would be appreciated.
    Mike King

    #300773 Reply

    MikeKing
    Member

    In my question, ‘DataModel’ should be replaced by ‘TableModel’ in the few places where I have made a mistake.
    Sorry.

    #300775 Reply

    MikeKing
    Member

    Should I just use the jdbc ResultSet methods to bind to DefaultTableModel?
    In this case I don’t use hibernate DAO classes etc.

    #300831 Reply

    Brian Fernandes
    Moderator

    Mike,

    Sorry for the delayed response. MyEclipse will not generate any code to automate the mapping of Hibernate objects to a DefaultTableModel.

    However, it should not be too difficult for you to extend DefaultTableModel and override a method like getValueAt(int, int) to return the correct value from the findAll() list.

    Re: Hibernate vs direct ResultSets, that really depends on the complexity of your application. Both Hibernate and ResultSets would work for a table model, but if you have many inter-related tables and a schema that will change over time, Hibernate will be easier in the long run.

    Hope this helps.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: How wire a database table to jTable (i.e. to a datamodel)

You must be logged in to post in the forum log in