wood burning stoves*
The moose likes JDBC and the fly likes insertion of Packed decimal data into Db2 table from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "insertion of Packed decimal data into Db2 table from Java" Watch "insertion of Packed decimal data into Db2 table from Java" New topic

insertion of Packed decimal data into Db2 table from Java

RajaAmirapu Sekhar

Joined: Aug 02, 2005
Posts: 1
Need help on storing packed decimal data into Db2 table from Java.

Our requirement is we need to store packed decimal data into Db2 table, which can be read successfully from Cobol program.

The structure of Db2 table is

01 Misc_info CHAR(256)
02 Drive_UpPACK(5,2)3 bytes
02 Tax_AmountPACK(7,2)4 bytes
02 Adj_DriveUpPACK(5,2)3 bytes

We are following the below specified steps to insert data into this table.

MainframeWriter mf = new MainframeWriter();

BigDecimal strDriveUp=new BigDecimal(strValue1);

BigDecimal strTaxAmount=new BigDecimal(strValue2);

BigDecimal strAdjDriveUp=new BigDecimal(strValue3);

byte[] buffer = mf.toByteArray();

ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(buffer, 0, buffer.length);
strMiscInfo = bos.toString(�Cp1047�);

And inserting the value of �strMiscInfo� in the Misc_Info field of DB2 table.

The value was inserted successfully, but when we are trying to read the same record and assigning the value of Misc_Info field to the working storage section fields as specified above. Sometimes it is giving errors and sometimes it is giving wrong values and some times it is correct values.

Could anyone guide us to resolve this problem?

Raja Sekhar
subject: insertion of Packed decimal data into Db2 table from Java
Similar Threads
Packed decimal conversion - Java
Rounding BigDecimal Calculation Yielded Wrong Result
rounding a fraction+time
Cp1047 Charecter Encoding to read JDBC string EBCDIC data.
String.getBytes("Cp1047") get wrong values for 25 and 15 for packed decimal value.