Mounesh Bhaskar
Mounesh Bhaskar

Reputation: 25

Issue with BigDecimal value in groovy : Retrieving diff value

I am using Groovy/Grails framework, I am fetching the Bigdecimal value from the mysql DB using the

Query = "select d.quantitativeData FROM MyTable d where d.segment.id = " + segmentid + 
" and d.sustainabilityIndicatorSubQuestion.id = "+questionid+" and d.tenantId= " +
TenantUtils.getCurrentTenant()+" order by d.id desc",[max:1]"

quantitativeData is a Bidgecimal variable.

But the value is retrieved from this query is like "0E-20" format, but the value in the database like '121.00000000000' , How to resolve this, can anybody help me out.

Thanks in advance.

Upvotes: 0

Views: 174

Answers (1)

Dónal
Dónal

Reputation: 187349

The BigDecimal is being converted to the string "0E-20", because you're constructing the query by concatenating strings together, rather than by using ? query placeholders.

If you use placeholders instead of string concatenation it will resolve this problem and also make you immune to SQL injection attacks.

Upvotes: 2

Related Questions