Five Stars

How to generate MD5 hash value

Hi All,
I want to generate MD5 checksum value to compare source and target data for all input columns. So that I can update the data in Target table only when there is change in Checksum value else reject. I goggle for user-defined routines but nothing helped.
I am very new to Talend and dont have much knowledge even on Java.
Helpful if someone could provide steps to do my job.
Regards
Keerthi

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: How to generate MD5 hash value

4 REPLIES
Twelve Stars

Re: How to generate MD5 hash value

You will need to use Java for this. This cannot really be made "easy" I'm afraid. Take a look here.....

https://www.quickprogrammingtips.com/java/how-to-generate-md5-hash-in-java.html

 

Referring to this I have put together a method that you can add to a routine.....

 

public static String getMD5(String data){
            java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            byte[] hash = digest.digest(data.getBytes("UTF-8"));

            return javax.xml.bind.DatatypeConverter.printHexBinary(hash);
}
Rilhia Solutions
Five Stars

Re: How to generate MD5 hash value

Thank you very much for your prompt response. I created the java routine in Talend using your code but unable to view under CATEGORIES.

How can I call the routine, how to pass input columns into the routine and how to compare them with the target/LKP table chksm value ? I tried using it in TMap but unable to proceed. Could you please help me.

Regards,

Keerthi

 

 

Twelve Stars

Re: How to generate MD5 hash value

Five Stars

Re: How to generate MD5 hash value

Thank You for the inputs @rhall_2_0. I modified the java code to suit my requirement and it worked.