Sonal
Sonal

Reputation: 321

How to pass a byte[] parameter type in a sql query in MyBatis?

I need to match against an encrypted column in the DB. I need to pass the encrypted value for matching as a byte[]. The hashcode of the byte[] is passed instead of the actual value stored in the byte[]. Because the hash code is passed, it does not match the value correctly. Below is my query and the function call in the Mapper.java.

AccBalNotificationBean selectAccBalNotificationBean(@Param("acctIdByteArray") byte[] acctIdByteArray);

SELECT toa.accounts_id from tbl_transactions_other_accounts toa WHERE other_account_number = #{acctIdByteArray}

Thank you for your help.

Upvotes: 1

Views: 3081

Answers (1)

Urobe
Urobe

Reputation: 280

I assume the datatype of your other_account_number column is of type string (char, varchar etc). Mybatis will use the StringDataTypeHandler by default and call the .toString() method of your byte array. Give MyBatis a hint that you want the content of your array to be used, by specifying the typeHandler.

.. WHERE other_account_number = #{acctIdByteArray, typeHandler=org.apache.ibatis.type.ByteArrayTypeHandler}

Upvotes: 2

Related Questions