Skip to content
Advertisement

Replace Parameters in SQL query text with XXXXX

I m writing a small utility that captures and logs SQL statements, but will have to remove sensitive data from the Query text and replace with with some dummy text (i.e:XXXXX).

What is a good way to parse the SQL query in java and replace parameters value?

for example:

replace

with

Advertisement

Answer

Using JSQLParser (V0.8.9) this is a solution for your problem:

This replaces all found String values within your SQL. To replace other types of data e.g. Long values, override the corresponding visit method in ExpressionDeParser.

Don’t use regexp in this case. It turns out quickly to be hard maintainable.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement