File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
Author

insertion of Packed decimal data into Db2 table from Java

RajaAmirapu Sekhar
Greenhorn

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);
strDriveUp=strDriveUp.setScale(2,BigDecimal.ROUND_HALF_UP);

BigDecimal strTaxAmount=new BigDecimal(strValue2);
strTaxAmount=strTaxAmount.setScale(2,BigDecimal.ROUND_HALF_UP);

BigDecimal strAdjDriveUp=new BigDecimal(strValue3);
strAdjDriveUp=strAdjDriveUp.setScale(2,BigDecimal.ROUND_HALF_UP);
mf.writePacked(strDriveUp,5,2,0);
mf.writePacked(strTaxAmount,7,2,0);
mf.writePacked(strAdjDriveUp,5,2,0);

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insertion of Packed decimal data into Db2 table from Java