Skip to content

Instantly share code, notes, and snippets.

Last active May 25, 2019 04:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Using prepared statements to protect against SQLI
String username = request.getParameter("username");
String password = request.getParameter("password");
String sqlAuthQuery = "select * from users where username = ? and password = ? ";
Connection connection = pool.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlAuthQuery);
preparedStatement.setString(1, username);
preparedStatement.setString(2, password);
ResultSet result = preparedStatement.executeQuery();
if ( {
loggedIn = true;
// Successfully logged in
} else {
// Auth failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment