• Добавление в связующую таблицу (many to many) через JDBC?

    @sambuca Автор вопроса
    MaxLich, public void addDevSkills(long id, long skillID) {
    List skillsID = new ArrayList<>();
    Statement statement = null;

    String sql1 = "SELECT * FROM skills";
    String sql2 = "INSERT INTO skills_developers VALUES (?,?)";
    try (Connection connection = ApplicationJDBC.getConnection()) {
    statement = connection.createStatement();
    ResultSet rs = statement.executeQuery(sql1);
    while (rs.next()) {
    long i = rs.getLong("id");
    if (skillsID != null) {
    skillsID.add(i);
    }
    }
    PreparedStatement preparedStatement = connection.prepareStatement(sql2);
    Developer developer = new Developer();
    for (Long sk_id : skillsID) {
    if (sk_id == skillID) {
    preparedStatement.setLong(1, developer.getId());
    preparedStatement.setLong(2, sk_id);
    }
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }