Decimal value into a database

S

Steven

Hi All,

I have a (SAS) database and I have to put into a field a decimal value.
The database field is of the Type -> Number


PreparedStatement st = conn_update.prepareStatement("UPDATE
m_usr.anomaly_param set susp_tolerance = ? where line_id = ?");

st.setInt(1, Integer.parseInt(request.getParameter("susp_tolerance")));
st.setInt(2, Integer.parseInt(request.getParameter("line_id")));


The value for 'susp_tolerance' is a decimal value which doesn't work with
'setInt'
also offcourse converting the parameter
"Integer.parseInt(request.getParameter("susp_tolerance"))" to an integer
doesn't work.

How would I do this for decimal values?

Thanks for any help!
 
S

Steven

Nope.
Got it working with :

st.setDouble(5, Double.parseDouble(request.getParameter("susp_tolerance")));
 
L

Lee Fesperman

Steven said:
Hi All,

I have a (SAS) database and I have to put into a field a decimal value.
The database field is of the Type -> Number

PreparedStatement st = conn_update.prepareStatement("UPDATE
m_usr.anomaly_param set susp_tolerance = ? where line_id = ?");

st.setInt(1, Integer.parseInt(request.getParameter("susp_tolerance")));
st.setInt(2, Integer.parseInt(request.getParameter("line_id")));

The value for 'susp_tolerance' is a decimal value which doesn't work with
'setInt'
also offcourse converting the parameter
"Integer.parseInt(request.getParameter("susp_tolerance"))" to an integer
doesn't work.

How would I do this for decimal values?

Try setBigDecimal().
 
?

=?iso-8859-1?q?Markus_B._Kr=FCger?=

Steven said:
Nope.
Got it working with :

st.setDouble(5, Double.parseDouble(request.getParameter("susp_tolerance")));

If you want the value stored in the database to be exactly the same as
the value you received, you should use setBigDecimal() like Lee
Fesperman suggested. Floating point numbers may be approximated. See
"Java theory and practice: Where's your point?"
(http://www-106.ibm.com/developerworks/java/library/j-jtp0114/) for
more on this topic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top