NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

adding sum column on jtable that is binded to a database table

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
GK



Joined: 01 Dec 2010
Posts: 6

PostPosted: Sun Dec 05, 2010 6:25 pm    Post subject: adding sum column on jtable that is binded to a database table Reply with quote

Hi all,

I have a database application very similar to this one:
http://netbeans.org/kb/65/java/gui-db-custom.html

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
Back to top
Sergio Medina
Posted via mailing list.





PostPosted: Mon Dec 06, 2010 2:08 am    Post subject: adding sum column on jtable that is binded to a database table Reply with quote

Try

SELECT c, SUM(c.orders.price) as ordersprice From Customer c

And map ordersprice

Regards

SM

-----Mensaje original-----
De: GK [mailto:address-removed]
Enviado el: domingo, 05 de diciembre de 2010 11:26 a.m.
Para: address-removed
Asunto: [nbusers] adding sum column on jtable that is binded to a database
table

Hi all,

I have a database application very similar to this one:
http://netbeans.org/kb/65/java/gui-db-custom.html

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
Back to top
GK



Joined: 01 Dec 2010
Posts: 6

PostPosted: Mon Dec 06, 2010 8:41 am    Post subject: Reply with quote

I tried changing the sql but didnt work, maybe I did something wrong though.

To make it work I created a property on the customer and set it as @Transient and then simply calculate the sum in the getter. Then I mapped the property on the table and worked perfectly.

Thanks! Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo