Is there any function or library which can be used to clean the user input. Like for example if the user input a text called baily's then i should escape the ' before sending it to mysql query. Similarly i should be able to filter null characters and \n, \t, \r etc.. Like in PHP we have mysql_real_escape_string($input) is there anything in Java to do this ?
Is there any function or library which can be used to clean the user
Share
In Java, you don’t usually do this by hand.
Instead you’ll use a
PreparedStatementand pass in any arguments to your SQL statement via explicitsetString()orsetObject()methods.This way the JDBC driver will handle it (either by doing the necessary escaping or by sending the SQL statement separately form the arguments, depending on the DB).
For example, your code could look like that (using
prepareStatement()):