title: get items from database according to jlist selected values and store in array
body: <p>I have a table <code>Users</code> in my database with columns <code>phone no</code> and <code>region</code>. In my GUI, I have a <code>JList</code> from where the user can select one or more regions, and accordingly I need to send out messages to the phone numbers with matching region. </p>
  
  <p>The problem I'm facing is in retrieving the phone numbers from the database.
  This is my code</p>
  
  <pre><code>        final JList listRegion = new JList(list);
          listRegion.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
          listRegion.setVisibleRowCount(3);
          JScrollPane scroll = new JScrollPane(listRegion);
          scroll.setBounds(113, 254, 123, 50);    
          frame.getContentPane().add(scroll);
  </code></pre>
  
  <p>I'm storing the selected list values like this</p>
  
  <pre><code>Object[] areaList = listRegion.getSelectedValues();
  </code></pre>
  
  <p>Now I need to retrieve all the numbers with their corresponding regions matching the regions in areaList and need to store them in an array.  I have tried something like this. But it seems to be wrong. </p>
  
  <pre><code>for( int i=0; i&lt;areaList.length ; i++){
      String sql2 = "select phone_no from users where region = areaList["+i+"]";
      result = statement.executeQuery(sql2);
  
      while(result.next()){
          String numbers = result.getString(1);
          //System.out.println(numbers);
      }
  } 
  </code></pre>
  
  <p>I am poor with arrays. Hence not able to do it. Please guide me with the correct way of doing this. </p>