-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cast varchar to double Problem
PostPosted: Thu Nov 03, 2011 6:53 am 
Newbie

Joined: Thu Nov 03, 2011 6:39 am
Posts: 2
Hi all,

in my DB I have a table mapped with the class Item and there is a column called prezzo that is a String in the java class and a varchar in the DB.

I need an hql query to sum all the values of prezzo. I have tried:

Code:
"SELECT SUM(CAST(item.prezzo AS  decimal(12,2))) from Item as item"

but the result is:
Code:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: expecting CLOSE, found '(' near line 1, column 40 [SELECT SUM(CAST(item.prezzo AS  decimal(12,2))) from skf.model.Item as item]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 40 [SELECT SUM(CAST(item.prezzo AS  decimal(12,2))) from skf.model.Item as item]




Then I tried:
Code:
"SELECT SUM(CAST(item.prezzo AS decfloat)) from Item as item"

but the result is:
Code:
Exception in thread "main" java.lang.NullPointerException at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:93)




Then I tried:
Code:
"SELECT SUM(CAST(item.prezzo AS double)) from Item as item"

but the result is:
Code:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'double precision)) as col_0_0_ from skf_items item0_' at line 1




Then I tried:
Code:
"SELECT SUM(CAST(CAST(item.prezzo AS decimal(12,2)) AS double)) from Item as item"

but the result is:
Code:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: expecting CLOSE, found '(' near line 1, column 44 [SELECT SUM(CAST(CAST(item.prezzo AS decimal(12,2)) AS double)) from skf.model.Item as item]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 44 [SELECT SUM(CAST(CAST(item.prezzo AS decimal(12,2)) AS double)) from skf.model.Item as item]





Then I tried:
Code:
"SELECT SUM(CAST(CAST(item.prezzo AS decfloat) AS double)) from Item as item"

but the result is:
Code:
Exception in thread "main" java.lang.NullPointerException at org.hibernate.dialect.function.CastFunction.render(CastFunction.java:36)



On each case i try to store the result this way:
Code:
List<Double> tots= (List<Double>) hibernateTemplate.find(sql);


I'm getting crazy for this. Can anybody help me please?

Thanks a lot.


Top
 Profile  
 
 Post subject: Re: Cast varchar to double Problem
PostPosted: Mon Nov 07, 2011 3:47 am 
Newbie

Joined: Thu Nov 03, 2011 6:39 am
Posts: 2
More info:

My column 'prezzo' is in the format: 214.15

Anybody can help? I cant find where iam I wrong.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


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

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.