timo.salmi Posted July 26, 2024 Posted July 26, 2024 (edited) Hi, I've got a hex value (source data to a reports comes from postgreSQL table) that I need to convert into a sting format in my report. Basic toString function doesn't work, it only shows the same hex value on a report as in the database. Is it possible to convert hex to string and if yes, how it's done? I'm using Jaspersoft Studio 6.20.6 Edited July 26, 2024 by timo.salmi
Solution Massimo Rabbi Posted July 31, 2024 Solution Posted July 31, 2024 Hi, I'm not sure how you are extracting your data and in which format (i.e byte, string etc.). Indeed, you should give a look at the java.util.HexFormat class introduced in Java 17. For example using such kind of expression into a text field (i.e simple report with one empty da) prints out a one page report with "TEST STRING". new String(java.util.HexFormat.of().parseHex("5445535420535452494e47")) This should enough and let you avoid adding 3rd party jars or create your own custom function. Regards, Massimo.
timo.salmi Posted August 12, 2024 Author Posted August 12, 2024 On 7/31/2024 at 4:08 PM, Massimo Rabbi said: Hi, I'm not sure how you are extracting your data and in which format (i.e byte, string etc.). Indeed, you should give a look at the java.util.HexFormat class introduced in Java 17. For example using such kind of expression into a text field (i.e simple report with one empty da) prints out a one page report with "TEST STRING". new String(java.util.HexFormat.of().parseHex("5445535420535452494e47")) This should enough and let you avoid adding 3rd party jars or create your own custom function. Regards, Massimo. Hi, thank you, testcode worked, when I tested it on my report. It didn't work with my original data though. I better explain myself: the data I'm using in my report, comes from PostgreSQL database vielä normal SELECT command (inside the report). Selected data is ip-addresses that postgreSQL stores in varchar in the following format: 00000000000000000000FFFFC0A80A0F. Ip-address is the last 8 digits. What I need is eiher same kind of a command to change the format or maybe better SQL select command to convert data when importing it. Any ideas? Regards, Timo
timo.salmi Posted August 16, 2024 Author Posted August 16, 2024 On 8/12/2024 at 11:30 AM, timo.salmi said: Hi, thank you, testcode worked, when I tested it on my report. It didn't work with my original data though. I better explain myself: the data I'm using in my report, comes from PostgreSQL database vielä normal SELECT command (inside the report). Selected data is ip-addresses that postgreSQL stores in varchar in the following format: 00000000000000000000FFFFC0A80A0F. Ip-address is the last 8 digits. What I need is eiher same kind of a command to change the format or maybe better SQL select command to convert data when importing it. Any ideas? Regards, Timo Hi, in addition to my previous message, I managed to create a SQL Select that converts the ip-address out of the hex value usin ldap function together with substr. All good and Solution marked. Although, if anyone has any other methods, feel free to answer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now