title: Insert values of arraylist into mysql table
body: <p>I am trying to insert values from arraylist into mysql table.  </p>
  
  <pre><code>List lstUnique=new ArrayList&lt;Object&gt;();
  //code to feed the data into list from resultset.
  try{          
      Class.forName("com.mysql.jdbc.Driver");
      con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MYdb","root","");
      stmt=con.createStatement();
      String sql1="select SourceFrom,Updated,Location_Type,Industry,ET_Rank,BT_Rank from mytable";
      rs1=stmt.executeQuery(sql1);
      rsmd=rs1.getMetaData();
      columnNumber=rsmd.getColumnCount();
  
      while(rs1.next()){
         lstUnique.add(rs1.getString("SourceFrom")+","+rs1.getString("Updated")+","+rs1.getString("Location_Type")+","+
                   rs1.getString("Industry")+","+rs1.getString("ET_Rank")+","+rs1.getString("BT_Rank")); 
      }
      String insertsql="";
      String SourceFrom=lstUnique.get(0).toString(); //its first column of the table.
      insertsql="Insert into java_uniquedata (SourceFrom,field2,field3,field4,field5) values(?,?,?,?,?)";
      PreparedStatement ps=con.prepareStatement(insertsql);
  
      //I tried this way also.
      for(int i=0;i&lt;lstUnique.size();i++){
          SourceFrom=lstUnique.get(i).toString();
      }
      for(int i=0;i&lt;lstUnique.size();i++){
          System.out.println("\n" + lstUnique.get(i).toString());
      }
      rs1.close();
      con.close();
  }catch(Exception e){
      System.out.println(e);
  }
  </code></pre>
  
  <p>But I am getting error</p>
  
  <blockquote>
    <p>java.lang.IndexOutOfBoundsException: Index: 1, Size: 1</p>
  </blockquote>
  
  <p>My list has only one record in it, which has total 5 columns' values. Can you guide me how do I fetch values of first record from arraylist and insert it into mysql table.     </p>