Filtering Single Quotes from all JTextAnything
Posted on 2007-04-11
I am working on a large swing/jdbc application. The application has a very large number of JTextField and JTextArea components which participate in the process of inserting / updating the database. The RDBMS we are using is mysql andhas a lot of issues when you are trying to insert characters such as SINGLE QUOTE.
I need to filter out this characters.
One solutions would be to do it manually on every single statement, but this would take ages, since there are hunderds of statements.
The other solution would be to somehow block the SINGLE QUOTE character.
What I would like is to find a way to do one of the following:
a) Replace JTextField with a custom component that extends JTextField and implements a kind of filtering. Using the focusLost event is not a very nice approach, as I would prefer the removal of that character to be more direct.
b) Find a way to catch as a keyTyped Event the insertion of SINGLE QUOTE and negate it.
c) Find a way to force the JRE to ignore the SINGLE QUOTE character.
d) Any other smart solution that would save me the trouble of checking all statements one by one.