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?
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?
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.
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
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();
}