Use prepared statement in java like below code segment and this will sql injection.this code is not vulnerable to SQL Injection because it correctly uses parameterized queries .it utilizes Java's PreparedStatement class, bind variables and the corresponding setString methods, SQL Injection can be easily prevented.
See this example:
String insert = "INSERT INTO QueryHomeUserDetails(name,email,interest) VALUES(?, ?, ?);"; //to bind variables
PreparedStatement preparedStatement = connection.prepareStatement(insert);
preparedStatement.setString(1, name);
preparedStatement.setString(2,email);
preparedStatement.setString(3,interest);
ResultSet resultSet = preparedStatement.executeQuery();