[
http://issues.apache.org/jira/browse/TORQUE-53?page=comments#action_12429900 ]
Sudhakar Pandey commented on TORQUE-53:
---------------------------------------
Thanks Monroe for your valuable reply. It really helped us alot in
understanding the problem.
As I have already mention in my second comment, we are facing this issue only
if the number is greater then seven digit, ends with zero and without non-zero
digits after decimal. For example we are facing issue with following type of
numbers:
123456780
123456780.00
Torque is behaving properly for following numbers(number not ending with zero
or has some non-zero digit after decimal; even when number is greater then 7
digit):
1234567890.0001
123456789
1234567890.1234
We are using JVM 1.5.0. I have testing the BigDecimal to Double conversion and
it seems to be working fine. Check the following code and its output:
<code>
......
public static void main(String[] args) {
// TODO Auto-generated method stub
Double value = new Double(1234567890);
System.out.println("Double value = " + value);
System.out.println("String value = " + value.toString());
System.out.println("Big Decimal value =" + new
BigDecimal(value.toString()));
}
......
</code>
<output>
Double value = 1.23456789E9
String value = 1.23456789E9
Big Decimal value =1.23456789E+9
</output>
Passing BigDecimal, in place of Double, as parameter, seems to be not possible
in our case, it will require huge-huge code change and we have yet to check
whether it will solve over problem or not.
> Inserting wrong data if data type is Double and 0(zero) is the last digit
> -------------------------------------------------------------------------
>
> Key: TORQUE-53
> URL: http://issues.apache.org/jira/browse/TORQUE-53
> Project: Torque
> Issue Type: Bug
> Affects Versions: 3.2
> Environment: Windows NT
> Reporter: Sudhakar Pandey
>
> Problem: Torque is inserting wrong data in the database for Double type.
> Database description
> ~~~~~~~~~~~~~~~~~
> Database: Oracle 10g
> Oracle JDBC version: 10.2.0.1.0
> Table Name: Bank_Account
> Column Name: Current_Balance
> Column dataType: NUMBER(15,4)
> When I am trying to enter a value new Double(1234567890) it insert/update
> 12.3456 in the database. This happens only if the number of digits are more
> than 7 and last digit is 0(zero).
> I have tried updating using directly PreparedStatement and it just worked
> fine. Problem comes only with Torque.
> Following is the program I have used for varification:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> <Code>
> ............
> public static void main(String argv[]) {
> TorqueInitializer.init();
> Connection db_connection = null;
> db_connection = Common.getConnection();
>
> if (db_connection == null) {
> System.out.println("Unable to get dbConnection");
> }
>
> try {
> BankAccount bankAccount =
> showCurrentBalance(db_connection);
> long value = 12345l;
> for (int i = 5; i < 11; i++, value = ((value * 10) +
> i)) {
> System.out.println("Value=" + value);
> System.out.print("<Before update> ");
> bankAccount = showCurrentBalance(db_connection);
>
> if (updateUsingPrepStat)
>
> updateCurrentBalanceUsingPStat(db_connection, new Double(
> value * 10));
> else
>
> updateCurrentBalanceUsingTorque(bankAccount, db_connection,
> new Double(value * 10));
> System.out.print("<After update> ");
> bankAccount = showCurrentBalance(db_connection);
> }
> } catch (Exception e) {
> e.printStackTrace();
> } finally {
>
> if (db_connection != null)
> try {
> db_connection.close();
> } catch (SQLException e) {
> e.printStackTrace();
> }
> }
> }
>
> public static BankAccount showCurrentBalance(Connection db_connection) {
> try {
> Criteria c = new Criteria();
> c.add(BankAccountPeer.BANK_ACCOUNT_ID, new
> Long(1523764));
> List list = BankAccountPeer.doSelect(c, db_connection);
> BankAccount bankAccount = (BankAccount) list.get(0);
> System.out.println("Current account balance: "
> + bankAccount.getCurrentBalance());
> return bankAccount;
> } catch (TorqueException e) {
> e.printStackTrace();
> }
> return null;
> }
>
> public static void updateCurrentBalanceUsingTorque(BankAccount
> bankAccount,
> Connection db_connection, Double value) throws
> Exception {
> bankAccount.setCurrentBalance(value);
> bankAccount.save(db_connection, "ibdv70");
> }
> ............
> </Code
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]