'Casting integer type on hexadecimal already formatted as string in Java

I have long (32 characters + leading 0x) hexadecimal value stored as string:

String key = '0x000639847445EB1570C9D9C92DAA1FB8'

For this to work, my query should look like this:

Select * from table where key = 0x000639847445EB1570C9D9C92DAA1FB8

It used to work with normal SQL statements but we changed it to Prepared Statement:

setString(preparedStatement, 1, key);

As we have the value in string, this is what it produces:

Select * from table where key = '0x000639847445EB1570C9D9C92DAA1FB8'

and our query does not return anything. Basically, I need to 'extract' the value from string format and apply another type to it without messing up the value, so my final query would have such format:

 Select * from table where key = 0x000639847445EB1570C9D9C92DAA1FB8

I have tried Byte.parseByte, adding this value to BigInt, however nothing seems to give result I'm looking for.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source