title: When executing an sql query, an error occurs, why?
body: <p>My database:</p>
  <p>Table Client:
  <a href="https://i.stack.imgur.com/PTXrL.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>The genderCode field is bound to the Gender table.</p>
  <p>Table Gender:
  <a href="https://i.stack.imgur.com/TCPH6.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>Request processing code:</p>
  <pre><code>public static ResultSet executeQuery (String sql) {
          ResultSet resultSet = null;
          System.out.println(sql);
          try {
              PreparedStatement preparedStatement = connection.prepareStatement(sql);
              if (sql.contains(&quot;SELECT&quot;)) {
                  resultSet = preparedStatement.executeQuery();
              } else {
                  preparedStatement.executeUpdate();
              }
          } catch (SQLException throwables) {
              throwables.printStackTrace();
  
          }
          return resultSet;
  
      }
  </code></pre>
  <p>Request: INSERT INTO client (FirstName, LastName, Patronymic, Birthday, RegistrationDate, Email, Phone, GenderCode, PhotoPath) VALUES ('111', '111', '111', '1999-10-10', '2021-04-14 10:09:28', '111', '111', 'м', '111')</p>
  <p>Error:
  Cannot add or update a child row: a foreign key constraint fails (<code>demotest</code>.<code>client</code>, CONSTRAINT <code>FK_Client_Gender</code> FOREIGN KEY (<code>GenderCode</code>) REFERENCES <code>gender</code> (<code>Code</code>) ON DELETE NO ACTION ON UPDATE NO ACTION)</p>
  <p>I pass the values to the request like this:</p>
  <pre><code>DBHandler.executeQuery(&quot;INSERT INTO client &quot; +
                                  &quot;(FirstName, LastName, Patronymic, Birthday, RegistrationDate, Email, Phone, GenderCode, PhotoPath) VALUES &quot; +
                                  &quot;('&quot;+firstName+&quot;', '&quot;+lastName+&quot;', '&quot;+patronymic+&quot;', '&quot;+birthday+&quot;', '&quot;+simpleDateFormat.format(regDate)+&quot;', '&quot;+email+&quot;', '&quot;+phone+&quot;', 'м', '&quot;+photoPath+&quot;')&quot;);
  </code></pre>
  <p>I can't use the PreparedStatement.setString because I don't know the amount of data being passed.</p>
  <p>How do I fix this error?</p>