We have several sensitive fields in our database which need to be prevented from entering the Java string pool. All are VARCHAR in the database and we use StringBuilders in our code to prevent them from being put in the constant pool.
We use MyBatis to interact with the database and I'm currently trying to implement a typehandler which I'm attempting to use setObject to map StringBuilder to Varchar to.
I'm wondering if this is possible and, if it is, are there other areas between MyBatis and the JDBC which mean that the VARCHAR not ending up in the String pool cannot be guaranteed? ( Casts in the code, statements coming as strings, that kind of thing )
I've asked the question on the mybatis-users google group as well but so far nobody has been able to help there
Edit - I should clarify that this isn't strictly about the string pool, it's about controlling where the data is on the heap and erasing the data from the mutable CharSequence as soon as possible by overwriting with nulls. The strings absolutely cannot go into the pool but simply nulling a string which is not in the pool can still lead to security issues due to how garbage collection works.