I have a field name varaince in a table set to type Number(20,3) in oracle..... I get number as string from the webpage and convert it to Double so I can write it back to table as shown be开发者_如何转开发low
if ( (this.getVariance() != null) && (this.getVariance().length() > 0) )
cstmt.setDouble(7,Util.stringToDouble(this.getVariance()));
else
cstmt.setNull(7,OracleTypes.NUMBER);
but i am getting this error
compile:
[exec] com\sample\common\javabean\ExampleBean.java:261: cannot resolve symbol
[exec] symbol : method setDouble (int,java.lang.Double)
[exec] location: interface java.sql.CallableStatement
[exec] cstmt.setDouble(7,Util.stringToDouble(this.getVariance()));
[exec]
^
when i was doing samething as integer it didnt give me error but it didnt write to table.
What can be done to convert string in such a way that table will write that number from the form. Any help would be good
Change Util.stringToDouble(this.getVariance())
to Util.stringToDouble(this.getVariance()).doubleValue()
.
details...
stringToDouble
seems to be returning a java.lang.Double
object. This means it is returning a reference to an object that actually carries the double on it. This is useful for anything that requires an Object
because Double
is an Object
.
doubleValue
returns a double
(lowercase). With this format, the actual 8 byte number is returned. This is more efficient because it does not require object allocation, but does not work when an Object
is required. However, in this case, the performance impact has done its damage because you are using stringToDouble
. You may consider using Double.parseDouble(...)
instead of Util.stringToDouble(...).doubleValue()
Do you really need to convert it to a double? You could do this:
cstmt.setBigDecimal(7, new java.math.BigDecimal(this.getVariance()));
精彩评论