title: how to get data from mysql to jList?
body: <p>I'm new in java.
  how can I get the data from mysql and display it in Jlist (Jlist name: JLISTF)
  I'm confused with vector and the model.</p>
  
  <p>Below is the photo of my JFRAME</p>
  
  <p>the yellow part means JLIST and it's name is JLISTF
  I want to display the data from mysql</p>
  
  <p>Thank you<img src="https://i.stack.imgur.com/Djzp6.png" alt="enter image description here"></p>
  
  <p>code:</p>
  
  <pre><code>public class Inventory extends javax.swing.JFrame {
  
  
          Connection connect = null;
          ResultSet rs = null;
          PreparedStatement pst = null;
          ResultSet rs2 = null;
  
  
      public void populateJList(JList ItemList, String query, Connection connection) throws SQLException
  {
      DefaultListModel model = new DefaultListModel(); //create a new list model
  
      Statement statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery(query); //run your query
  
      while (resultSet.next()) //go through each row that your query returns
      {
          String ItemList2 = resultSet.getString("ItemCode"); //get the element in column "item_code"
          model.addElement(ItemList2); //add each item to the model
      }
      ItemList.setModel(model);
  
      resultSet.close();
      statement.close();
  
  }
  
  
  public Inventory() {..}
  
    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) { ......}
  
  private void saveButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  String inventcodef = inventCodeField.getText();
  try{.........}
  catch()
  {...........}
  }
  </code></pre>