title: How do I pass data from jList to database(mySQL)
body: <p>I need some help regarding my program. How do I pass data from JList into database?</p>
  
  <p>In ItemDetails.java, I have passed the checkbox value into a JList in another JForm. Now I want to retrieve the data from JList into my database.</p>
  
  <p>ItemDetails.java</p>
  
  <pre><code>    private void jButtonNextActionPerformed(java.awt.event.ActionEvent evt) {                                            
  
      ShoppingCart sc=new ShoppingCart();
               if(!jCheckBoxAdele.isSelected()&amp;&amp;!jCheckBox1DPerfect.isSelected()&amp;&amp;!jCheckBoxBieber.isSelected()
              &amp;&amp;!jCheckBox1D1Thing.isSelected()&amp;&amp;!jCheckBoxHujan.isSelected()&amp;&amp;!jCheckBoxSamWriting.isSelected()
              &amp;&amp;!jCheckBoxAlessiaWil.isSelected()&amp;&amp;!jCheckBoxSamStayWithMe.isSelected()
              &amp;&amp;!jCheckBoxFx.isSelected()&amp;&amp;!jCheckBoxSonaone.isSelected()&amp;&amp;!jCheckBoxRabbani.isSelected()
              &amp;&amp;!jCheckBoxTroye.isSelected()&amp;&amp;!jCheckBoxMarvinGaye.isSelected())
      {
  
        sc.setVisible(false);
  
       JOptionPane.showMessageDialog(null, "Please pick your song !!!");
       dispose();
       new ItemDetails().setVisible(true);
      }
  
  
      if(jCheckBoxAdele.isSelected())
          songsdetails.add("Adele - Hello");
  
      if(jCheckBox1DPerfect.isSelected())
          songsdetails.add("One Direction - Perfect");
  
      if(jCheckBoxBieber.isSelected())
          songsdetails.add("Justin Bieber - Sorry");
  
      if(jCheckBox1D1Thing.isSelected())
          songsdetails.add("One Direction - One Thing");
  
      if(jCheckBoxHujan.isSelected())
          songsdetails.add("Hujan - Anging Kencang");
  
      if(jCheckBoxSamWriting.isSelected())
          songsdetails.add("Sam Smith - Writing On The Walls");
  
      if(jCheckBoxAlessiaWil.isSelected())
          songsdetails.add("Alessia Cara");
  
      if(jCheckBoxSamStayWithMe.isSelected())
          songsdetails.add("Sam Smith - Stay With Me");
  
      if(jCheckBoxFx.isSelected())
          songsdetails.add("F(x) - 4 Walls");
  
      if(jCheckBoxDemi.isSelected())
          songsdetails.add("Demi Lovato - I Really Don't Care");
  
      if(jCheckBoxSonaone.isSelected())
          songsdetails.add("Sonaone - Firefly");
  
      if(jCheckBoxRabbani.isSelected())
          songsdetails.add("Rabbani - Pergi Tak Kembali");
  
      if(jCheckBoxTroye.isSelected())
          songsdetails.add("Troye Sivan - Fools");
  
      if(jCheckBoxMarvinGaye.isSelected())
          songsdetails.add("Charlie Puth - Marvin Gaye");
  
          new ShoppingCart(songsdetails).setVisible(true);
          dispose(); 
  
  }         
  </code></pre>
  
  <p>ShoppingCart.java</p>
  
  <pre><code>public class ShoppingCart extends javax.swing.JFrame {
  public Connection cn;
  public PreparedStatement st;
  static ArrayList songsdetails;
  
  /**
   * Creates new form ShoppingCart
   */
  public ShoppingCart() {
      initComponents();
  }
  
  public ShoppingCart(ArrayList SONGSDETAILS) {
      initComponents();
      songsdetails = SONGSDETAILS;
  }               
  private void jButtonEditActionPerformed(java.awt.event.ActionEvent evt) {                                            
  
      this.setVisible(false);
      jList1.clearSelection();
      new ItemDetails().setVisible(true);
  
  }                                           
  
  private void jButtonNextActionPerformed(java.awt.event.ActionEvent evt) {                                            
  
  
          try {
              Class.forName("com.mysql.jdbc.Driver");
  
              cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sdmusic","root","");
  
              st=cn.prepareStatement("SELECT `Username`, `SongsSelection` FROM `user` WHERE `Username`=?  'SongsSelection' = ?");
  
  
  
  
  
          } catch (ClassNotFoundException ex) {
              Logger.getLogger(ShoppingCart.class.getName()).log(Level.SEVERE, null, ex);
          } catch (SQLException ex) {
          Logger.getLogger(ShoppingCart.class.getName()).log(Level.SEVERE, null, ex);
      }
  
     dispose();
     new CalculatePay().setVisible(true);
  
  }                                           
  
  private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
      // TODO add your handling code here:
      DefaultListModel list = new DefaultListModel();
      System.out.println(""+songsdetails.get(0));
      for(int i=0; i &lt;songsdetails.size();i++){
          list.addElement(songsdetails.get(i));
      }
      jList1.setModel(list);
  
  
  }                                 
  </code></pre>