Jump to content

How to convert hex value to string in a report


Go to solution Solved by Massimo Rabbi,

Recommended Posts

Posted (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 by timo.salmi
  • timo.salmi changed the title to How to convert hex value to string in a report
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution
Posted

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.

  • 2 weeks later...
Posted
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

Posted
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. 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...