title: Drop down list implement with mysql and jdbc
body: <p>I have two tables. First table Profession with two columns (profession_id, profession_name).
  Second table Applicant with five columns (applicant_id, profession_id, last_name, first_name, entrance_year).
  "profession_id" in table Applicant and "profession_id" in table Profession is related fields in mysql.</p>
  
  <pre><code>CREATE TABLE PROFESSION (
    PROFESSION_ID   INT         NOT NULL AUTO_INCREMENT,
    PROFESSION_NAME VARCHAR(50) NOT NULL,
    PRIMARY KEY (PROFESSION_ID)
  );
  
  CREATE TABLE APPLICANT (
    APPLICANT_ID  INT         NOT NULL AUTO_INCREMENT,
    PROFESSION_ID INT         NOT NULL,
    LAST_NAME     VARCHAR(30) NOT NULL,
    FIRST_NAME    VARCHAR(30) NOT NULL,
    ENTRANCE_YEAR INT         NOT NULL,
    PRIMARY KEY (APPLICANT_ID),
    FOREIGN KEY (PROFESSION_ID) REFERENCES PROFESSION (PROFESSION_ID)
  );
  </code></pre>
  
  <p>This is my class, that working with DB:</p>
  
  <pre><code>public enum ApplicantDBProvider {
  
      INSTANCE;
  
      private Connection connection;
  
      private ApplicantDBProvider() {
          try {
              Class.forName("com.mysql.jdbc.Driver");
              connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_applicant", "root", "toor");
          } catch (ClassNotFoundException | SQLException e) {
              System.err.println("Class not found: com.mysql.jdbc.Driver " + e);
              throw new RuntimeException("Class not found: com.mysql.jdbc.Driver");
          }
      }
  
      public Applicant getApplicant(long applicantId) throws Exception {
          PreparedStatement preparedStatement = null;
          Applicant applicant = null;
          try {
              preparedStatement = connection.prepareStatement("SELECT * FROM applicant WHERE applicant_id=?");
              preparedStatement.setInt(1, (int) applicantId);
  
              ResultSet resultSet = preparedStatement.executeQuery();
              while (resultSet.next()) {
                  applicant = new Applicant();
                  applicant.setId(resultSet.getInt("applicant_id"));
                  applicant.setFirstName(resultSet.getString("first_name"));
                  applicant.setLastName(resultSet.getString("last_name"));
                  applicant.setProfessionId(resultSet.getInt("profession_id"));
                  applicant.setEntranceYear(resultSet.getInt("entrance_year"));
              }
          } catch (SQLException e) {
              e.printStackTrace();
          } finally {
              if (preparedStatement != null) {
                  preparedStatement.close();
              }
          }
  
          return applicant;
      }
  
      public List&lt;Applicant&gt; getApplicants() throws Exception {
          Statement statement = null;
          List &lt;Applicant&gt; applicants = new ArrayList&lt;&gt;();
  
          try {
              statement = connection.createStatement();
              ResultSet resultSet = statement.executeQuery("SELECT * FROM applicant");
              Applicant applicant = null;
              while (resultSet.next()) {
                  applicant = new Applicant();
                  applicant.setId(resultSet.getInt("applicant_id"));
                  applicant.setFirstName(resultSet.getString("first_name"));
                  applicant.setLastName(resultSet.getString("last_name"));
                  applicant.setProfessionId(resultSet.getInt("profession_id"));
                  applicant.setEntranceYear(resultSet.getInt("entrance_year"));
                  applicants.add(applicant);
  
              }
  
          } catch (SQLException e) {
              throw new Exception(e);
          }
  
          return applicants;
      }
  
      public void saveApplicant(Applicant applicant) throws Exception {
          PreparedStatement preparedStatement = null;
  
          try {
              if (applicant.getId() == -1) {
                  preparedStatement = connection.prepareStatement("INSERT INTO applicant (first_name, last_name, profession_id, entrance_year) VALUES (?,?,?,?)");
  
                  preparedStatement.setString(1, applicant.getFirstName());
                  preparedStatement.setString(2, applicant.getLastName());
                  preparedStatement.setInt(3, (int)applicant.getProfessionId());
                  preparedStatement.setInt(4, applicant.getEntranceYear());
  
              } else {
                  preparedStatement = connection.prepareStatement("UPDATE applicant SET first_name=?, last_name=?, profession_id=?, entrance_year=?  WHERE applicant_id=?");
  
                  preparedStatement.setString(1, applicant.getFirstName());
                  preparedStatement.setString(2, applicant.getLastName());
                   preparedStatement.setInt(3, (int) applicant.getProfessionId());
                  preparedStatement.setInt(4, applicant.getEntranceYear());
                  preparedStatement.setInt(5, (int) applicant.getId());
              }
              preparedStatement.executeUpdate();
          } catch (SQLException e) {
              throw new Exception(e);
          } finally {
              if (preparedStatement != null) {
                  preparedStatement.close();
              }
          }
      }
  
      public void deleteApplicant(long applicantId) throws Exception {
          PreparedStatement preparedStatement = null;
  
          try {
              preparedStatement = connection.prepareStatement("DELETE FROM applicant WHERE applicant_id=?");
  
              preparedStatement.setInt(1, (int) applicantId);
              preparedStatement.executeUpdate();
          } catch (SQLException e) {
              throw new Exception(e);
          } finally {
              if (preparedStatement != null) {
                  preparedStatement.close();
              }
          }
      }
  
      public Profession getProfession(long professionId) throws Exception {
          PreparedStatement preparedStatement = null;
          Profession profession = null;
          try {
              preparedStatement = connection.prepareStatement("SELECT * FROM profession WHERE profession_id=?");
              preparedStatement.setInt(1, (int) professionId);
  
              ResultSet resultSet = preparedStatement.executeQuery();
              while (resultSet.next()) {
                  profession = new Profession();
                  profession.setId(resultSet.getInt("profession_id"));
                  profession.setProfessionName(resultSet.getString("profession_name"));
              }
          } catch (SQLException e) {
              e.printStackTrace();
          } finally {
              if (preparedStatement != null) {
                  preparedStatement.close();
              }
          }
  
          return profession;
      }
  
      public List&lt;Profession&gt; getProfessions() throws Exception {
          Statement statement = null;
  
          List&lt;Profession&gt; professions = new ArrayList&lt;&gt;();
          try {
              statement = connection.createStatement();
              ResultSet resultSet = statement.executeQuery("SELECT * FROM profession");
              Profession profession = null;
              while (resultSet.next()) {
                  profession = new Profession();
                  profession.setId(resultSet.getInt("profession_id"));
                  profession.setProfessionName(resultSet.getString("profession_name"));
                  professions.add(profession);
              }
  
          } catch (SQLException e) {
              throw new Exception(e);
          } finally {
              if (statement != null) {
                  statement.close();
              }
          }
  
          return professions;
      }
  
      public void saveProfession(Profession profession) throws Exception {
          PreparedStatement preparedStatement = null;
  
          try {
              if (profession.getId() == -1) {
                  preparedStatement = connection.prepareStatement("INSERT INTO profession (profession_name) VALUES (?) ");
  
                  preparedStatement.setString(1, profession.getProfessionName());
              } else {
                  preparedStatement = connection.prepareStatement("UPDATE profession SET profession_name=? WHERE profession_id=?");
  
                  preparedStatement.setString(1, profession.getProfessionName());
                  preparedStatement.setInt(2, (int) profession.getId());
              }
              preparedStatement.executeUpdate();
          } catch (SQLException e) {
              throw new Exception(e);
          } finally {
              if (preparedStatement != null) {
                  preparedStatement.close();
              }
          }
  
      }
  
      public void deleteProfession(long professionId) throws Exception {
          PreparedStatement preparedStatement = null;
  
          try {
              preparedStatement = connection.prepareStatement("DELETE FROM profession WHERE profession_id=?");
  
              preparedStatement.setInt(1, (int) professionId);
              preparedStatement.executeUpdate();
          } catch (SQLException e) {
              throw new Exception(e);
          } finally {
              if (preparedStatement != null) {
                  preparedStatement.close();
              }
          }
      }
  </code></pre>
  
  <p>This is working good. But i need, instead of profession_id, get a drop down list of available profession. I hear, that implemented with INNER JOIN. But how to do this, i dont know. Please help. And i'm sorry that you need to read a lot of code. Thanks.</p>