Search code examples
javajdbcibm-midrangejt400

AS400 SQL Script on a parameter file returns


I'm integrating an application to the AS400 using Java/JT400 driver. I'm having an issue when I extract data from a parameter file - the data retrieved seems to be encoded.

SELECT SUBSTR(F00001,1,20) FROM QS36F."FX.PARA" WHERE K00001 LIKE '16FFC%%%%%' FETCH FIRST 5 ROWS ONLY

Output

00001: C6C9D9C540C3D6D4D4C5D9C3C9C1D34040404040,  - 1
00001: C6C9D9C5406040C3D6D4D4C5D9C3C9C1D3406040,  - 2

How can I convert this to a readable format? Is there a function which I can use to decode this?

On the terminal connection to the AS400 the information is displayed correctly through the same SQL query.

I have no experience working with AS400 before this and could really use some help. This issue is only with the parameter files. The database tables work fine.


Solution

  • What you are seeing is EBCDIC output instead of ASCII. This is due to the CCSID not being specified in the database as mentioned in other answers. The ideal solution is to assign the CCSID to your field in the database. If you don't have the ability to do so and can't convince those responsible to do so, then the following solution should also work:

    SELECT CAST(SUBSTR(F00001,1,20) AS CHAR(20) CCSID(37))
    FROM QS36F."FX.PARA"
    WHERE K00001 LIKE '16FFC%%%%%'
    FETCH FIRST 5 ROWS ONLY
    

    Replace the CCSID with whichever one you need. The CCSID definitions can be found here: https://www-01.ibm.com/software/globalization/ccsid/ccsid_registered.html