title: How to execute a SQL statement in Java with variables
body: <p>I have the following mysql statement to delete records from a DB that is working.</p>
  
  <pre><code>SET @email = 'delete@mailinator.com';
  SET @userID = (SELECT id FROM USER WHERE email = @email);
  DELETE FROM user_role_group WHERE user_id = @userID;
  DELETE FROM user_client_setup WHERE user_id = @userID;
  DELETE FROM USER WHERE id = @userID;
  </code></pre>
  
  <p>I want to run this same query in Java with a jdbc mysql connection. I have tried the following</p>
  
  <pre><code>public void deleteCoreUser(String email) {
          try{
              Class.forName("com.mysql.cj.jdbc.Driver");
              Connection con=DriverManager.getConnection(
                      "jdbc:mysql://db.com:3306/core","username","password");
              Statement stmt=con.createStatement();
              ResultSet rs=stmt.executeQuery("SET @email = '"+email+"';\n" +
                      "SET @userID = (SELECT id FROM user WHERE email = @email);\n" +
                      "DELETE FROM user_role_group WHERE user_id = @userID;\n" +
                      "DELETE FROM user_client_setup WHERE user_id = @userID;\n" +
                      "DELETE FROM user WHERE id = @userID;");
              con.close();
              System.out.println("Deleting user "+email+" from the Core DB");
          }catch(Exception e){ System.out.println(e);}
      }
  </code></pre>
  
  <p>I am getting this error when running</p>
  
  <blockquote>
    <p>java.sql.SQLSyntaxErrorException: You have an error in your SQL
    syntax; check the manual that corresponds to your MariaDB server
    version for the right syntax to use near 'SET @userID = (SELECT id
    FROM user WHERE email = @email); DELETE FROM user_role_' at line 2</p>
  </blockquote>