Java – escape string to prevent SQL injection
PreparedStatements are the way to go, because they make SQL injection impossible. Here’s a simple example taking the user’s input as the parameters: public insertUser(String name, String email) { Connection conn = null; PreparedStatement stmt = null; try { conn = setupTheDatabaseConnectionSomehow(); stmt = conn.prepareStatement(“INSERT INTO person (name, email) values (?, ?)”); stmt.setString(1, name); stmt.setString(2, … Read more