2

Hi,

I have database in MySql and want to get my table to be bind with Swing JTable. Now my DAO class retrieves data from my table and stores it into java.util.List. What approaches I could use to bind db table with JTable?

1
  • There is no good way to do this, probably allot of complex answers to this but they could be simplified to that you have your application state located in 2 positions, rather just send updates every few minutes, but this doesn't scale nicely. Commented Jul 20, 2015 at 2:45

2 Answers 2

1

As you have data fetched from Database wrapped by DAO, using DAO put those information in relevant row/column of your JTable.

Here are SO Question and answer for your requirement. Hope they will help you.

Populate JTable Using List

Java GUI aplication, load data to Jtable from a list<objects>

How to add data to JTable created in design mode?

Other Resources.

http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

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

1 Comment

Thanks, but I found that it is better to use JTable(tablemodel) constructor with connection to database. Does someone has an expirience with using TableModel?
0
 Session sesion = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;
    try {
        tx = sesion.beginTransaction();
        List today = sesion.createQuery("FROM class WHERE something").list();
     for (Iterator iterator = today.iterator(); iterator.hasNext();){
        Salidas Sal = (Salidas) iterator.next(); 
        tablemodel.addRow(new Object[]{
            //`enter code here`columns
            Sal.getId(),
            Sal.getUsuarios().getNombre().toString(),
            Sal.getCantidadPrestada(),
            Sal.getCantidadPedida(),
            Sal.getFechaSalida()});
        }
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
    } finally {
        sesion.close();
    }

Comments

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.