title: Multiple Select Dao Mysql Spring MVC
body: <p>I want to build in a select with the possibility of marking more elements. So <code>multiple="true"</code>. I use mysql and the Dao Technology of spring. I get the values for the select from database successfully. But now I have a problem when inserting the selected values to my database.</p>
  
  <p>The important tables for that are:</p>
  
  <p><img src="https://i.stack.imgur.com/lwepP.png" alt="desc"></p>
  
  <p>The table <code>demo.instrumente</code> is filled with data like <code>guitar</code>, <code>piano</code>, etc. and an <code>id</code>. These values (i.e. <code>guitar</code>, <code>piano</code>) are displayed in the multiple select.</p>
  
  <p>A user is able to select maybe 2 or 3 instruments. So I need to add the following instruments to the students. I do this with the table <code>schueler_instrumente</code>. Every <code>student</code> and <code>instrument</code> has an <code>id</code>. So i need to create data like this:</p>
  
  <pre><code>student_id 1 and instrument_id 2
  student_id 1 and instrument_id 5
  </code></pre>
  
  <p>Here is my code for the instrument model class:</p>
  
  <pre><code>public class Instrumente {
  
    private Integer instrumentid;
    private String instrumentname;
  
    //...getters and setters
  }
  </code></pre>
  
  <p>This code is part of my controller:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET)
  public String showUserForm(ModelMap model) {
    model.put("instrumentListe", schuelerManager.getinstrumente());
    return "usercenter";
  }
  </code></pre>
  
  <p>And here's the relevant part of my schuelerManager</p>
  
  <pre><code>public Map&lt;String, String&gt; getinstrumente() {
    Map&lt;String,String&gt; result = new LinkedHashMap&lt;String,String&gt;();
    for (Instrumente instrument : instrumentDao.getInstrumente()) {
      result.put(instrument.getInstrumentid().toString(),
                 instrument.getInstrumentname());
    }
    return result;
  }
  </code></pre>
  
  <p>And here's how I get the data from my database:</p>
  
  <pre><code>public  List&lt;Instrumente&gt; getInstrumente() {
  
    return getJdbcTemplate().query("SELECT * FROM instrumente",
                                   new RowMapper&lt;Instrumente&gt;() {
                                     public Instrumente mapRow(ResultSet rs,
                                                               int rowNum)
                                       throws SQLException {
                                       Instrumente instrument = new Instrumente();
                                       instrument.setInstrumentid
                                         (rs.getInt("Instrument_ID"));
                                       instrument.setInstrumentname
                                         (rs.getString("Instrumentenbezeichnung"));
                                       return instrument;
                                     }
                                   });
  }
  </code></pre>
  
  <p>I do now know what I need to do in order to get the selected values from the select list. What do I have to write to the <code>path="?"</code> in the jsp.</p>
  
  <p>I think that I can get a list of values back but how can I insert this list to my table <code>schueler_instrument</code>. Did I need to make a while or for repeat and make an insert everytime?
  I can't find any nice example on the Internet. I hope someone can show me how to do this maybe with some code snippets.</p>