Results 1 to 5 of 5
- 12-05-2010, 06:08 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 9
- Rep Power
- 0
adding sum column on jtable that is binded to a database table
Hi all,
I hope this is the correct thread to make this post.
I have a database application created with NetBeans very similar to this one:
Creating a Custom Java Desktop Database Application - NetBeans 6.5 Tutorial
I would like to add another column on the customer (master) table that will display the sum of the orders cost that each customer has done.
I dont think I need to create another column on the database table to hold that value. I tried to create a new property on the Customer entity but it requires that this property exists in the database table as well so I removed the new property.
I also tried to change the query to
SELECT c, SUM(c.orders.price) From Customer c
and then map the sum to the appropriate column but also didnt work.
Any ideas on how I could make this work?
Thank you
GK
-
My guess is that you'll need to change the TableModel for the JTable to have one more column and then override the table model's getValueAt method to display a sum of data from the row. What kind of TableModel are you currently using?
- 12-05-2010, 07:03 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 9
- Rep Power
- 0
Thanks for the quick reply.
I m using the autogenerated table model. I believe its the default one. This is the code for the customerTable:
I can add a column but I m not sure how the binding can be done. I was thinking something like:Java Code:customerTable.setName("customerTable"); // NOI18N org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, customerTable); org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custSurname}")); columnBinding.setColumnName("Cust Surname"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custName}")); columnBinding.setColumnName("Cust Name"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custTel}")); columnBinding.setColumnName("Cust Tel"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custAddr}")); columnBinding.setColumnName("Cust Addr"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${comments}")); columnBinding.setColumnName("Comments"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ObjectProperty.create()); columnBinding.setEditable(false); bindingGroup.addBinding(jTableBinding); jTableBinding.bind();
jTableBinding.addColumnBinding(org.jdesktop.beansb inding.ELProperty.create("${customer.orders.price} "));
but it is not allowed by netbeans and its not working since it also needs to get a sum function in there somehow.
I also have created a query that returns the customers with the total price of each ones orders but I dont think this is how it will work since the data is binded directly to the table.
:confused:
Thanks,
GK
- 12-06-2010, 03:59 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 2
- Rep Power
- 0
You should try adding a transient field in customer entity class and setting sum value to it.
- 12-06-2010, 08:26 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
JTable and AUTO_RESIZE_OFF and column resize creating extra sapce on end of table.
By asifu9 in forum AWT / SwingReplies: 0Last Post: 11-02-2010, 12:23 PM -
selecting column names dynamically from table column header
By neha_sinha in forum AWT / SwingReplies: 1Last Post: 07-06-2010, 04:50 PM -
Adding JComboBox type column to the JTable ??
By Stephen Douglas in forum New To JavaReplies: 2Last Post: 04-10-2010, 03:03 PM -
Updating database table from JTable
By yesjava in forum New To JavaReplies: 1Last Post: 08-16-2008, 10:16 PM -
Problem with jTable that is binded with a table in MySQL Database
By rajkenneth in forum NetBeansReplies: 0Last Post: 03-29-2008, 03:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks