jdbc - Is there any way to prevent Java from turning my double into exponential value? -
Does Java have to stop changing its double into exposition value? I am having trouble saving my database, it keeps telling me that it can not convert my warcurter to a numerical form.
I do;
amt = oldAmt - amt; AMT = Math ABS (AMT);
Use the value as a setter in AMT ;
jvd.setDr_amt (AMT);
Then generate a query string using a function and it gives me;
INSERT (1, 1.595545786E7) in jv (id, dr_amt) values;
I'm very convinced that you do something like this:
connection.createStatement (). ExecuteUpdate (enter "My_table VALUES ('" + myDouble + "')"); Do not do this for the following reasons: - Adding a string will cause syntax errors
- String section causes SQL injection
Write your statement to allow JDBC to handle data types:
generated statement stmt = connection.prepareStatement ("my_table values (INSERT My_table VALUES?) "); Stmt.setDouble (1, myDouble); Stmt.executeUpdate ();
If you use sentences in double quote inline in your SQL string instead of bound values,
BigDecimal
By using your double, instead of: New Business (myDouble) .toString ();
Since you are working on monetary values, you should convert all your doubles to BigDecimal
, as BigDecimal
Java is the best match for SQL's DCIMAL
data type
Comments
Post a Comment