There is a database, it has 2 entities and a many to many connection, I create a DAO for crud operations, then the question arises, I want to create a developer and add skill to it. How do I add data to the skills_developers table?
/*Create table developers*/ CREATE TABLE developers ( id INT NOT NULL PRIMARY KEY, name VARCHAR(100) NOT NULL salary VARCHAR(100) NOT NULL ); /*Create table skills*/ CREATE TABLE skills ( id INT NOT NULL PRIMARY KEY, name VARCHAR(100) NOT NULL ); /*Create table skill_developers with links*/ CREATE TABLE skills_developers ( dev_id INT NOT NULL, sk_id INT NOT NULL, FOREIGN KEY (dev_id) REFERENCES developers (id), FOREIGN KEY (sk_id) REFERENCES skills (id) ); public void addDevSkills(String dev_name, String sk_name) { String sql = "INSERT INTO skills_developers (dev_id, sk_id) " + "SELECT developers.id, skills.id " + "FROM developers, skills " + "WHERE d.name = ? AND s.name = ?"; try (Connection connection = ApplicationJDBC.getConnection()) { PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, developer.getFullName()); preparedStatement.setString(2, skill.getName()); } catch (SQLException e) { e.printStackTrace(); } } Why not add to the table ??