Background:
I am currently developing a Java front panel for the Enterprise CMS (Business Objects) database. At the moment, I am creating a function that allows the user to create a user database query. I have already implemented measures so that the user can select only a subset of the available columns and operators that have been approved for user access (for example, SI_EMAIL_ADDRESS can be selected, while stronger fields such as SI_CUID cannot be). So far, everything is going smoothly, but the time has come to protect this feature from possible SQL injection attacks.
Question:
I am looking for a way to avoid entering custom strings. I have already seen PerparedStatement, however I am forced to use third-party APIs to access the database. These APIs are immutable for me, and direct access to the database is out of the question. Individual methods accept strings representing the queries that will be executed, thereby invalidating the PreparedStatement (which, as far as I know, should be executed against a direct connection to the database).
I have considered using String.replace (), but I don't want to reinvent the wheel, if possible. In addition, I am far from the security experts who developed the PerparedStatement.
I also looked at the Java API reference for PerparedStatement, hoping to find some toString () method. Alas, I could not find anything like it.
Any help is appreciated. Thank you in advance.
Literature:
Java - escape string to prevent SQL injection
Java equivalent for mysql_real_escape_string ()
source share