title: working for MySQL connect in java. Why am I getting java.lang.IndexOutOfBoundsException error?
body: <pre><code>sorry im first
  </code></pre>
  <blockquote>
  <p><strong>library</strong> mysql-connector-java-8.0.25.jar, jsoup-1.13.1.jar</p>
  </blockquote>
  <blockquote>
  <p>import</p>
  </blockquote>
  <pre><code>import java.io.IOException;
  import java.net.URL;
  import java.net.URLEncoder;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.nodes.Element;
  import org.jsoup.select.Elements;
  public class SQLLostProperty {
  </code></pre>
  <pre><code>public static void main(String[] args) throws IOException {
      StringBuilder urlBuilder = new StringBuilder(&quot;http://apis.data.go.kr/1320000/LosfundInfoInqireService/getLosfundInfoAccToClAreaPd&quot;); /*URL*/
      urlBuilder.append(&quot;?&quot; + URLEncoder.encode(&quot;serviceKey&quot;,&quot;UTF-8&quot;) + &quot;=wLnaMueBw2fSWQSMJ0m9J5oPYpaQsysWiHAWpJ%2BkJcHu09yps%2FMksIuW07Sp%2FS4%2FebmwCJP55bL9kZebODnI%2Bg%3D%3D&quot;); /*Service Key*/
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;PRDT_CL_CD_01&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;PRH000&quot;, &quot;UTF-8&quot;));
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;PRDT_CL_CD_02&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;PRH200&quot;, &quot;UTF-8&quot;)); 
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;START_YMD&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;20120302&quot;, &quot;UTF-8&quot;)); 
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;END_YMD&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;20211009&quot;, &quot;UTF-8&quot;)); 
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;N_FD_LCT_CD&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;LCA000&quot;, &quot;UTF-8&quot;));
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;pageNo&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;1&quot;, &quot;UTF-8&quot;)); /*페이지 번호*/
      urlBuilder.append(&quot;&amp;&quot; + URLEncoder.encode(&quot;numOfRows&quot;,&quot;UTF-8&quot;) + &quot;=&quot; + URLEncoder.encode(&quot;99999&quot;, &quot;UTF-8&quot;)); 
      URL url = new URL(urlBuilder.toString());        
      ArrayList&lt;String&gt; atcId = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; clrNm = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; depPlace = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; fdPrdtNm = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; fdSbjt = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; fdYmd = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; prdtClNm = new ArrayList&lt;String&gt;(10000);
      ArrayList&lt;String&gt; rnum = new ArrayList&lt;String&gt;(10000);
   
      
      ArrayList&lt;ArrayList&gt; order = new ArrayList&lt;ArrayList&gt;();
      order.add(atcId);
      order.add(clrNm);
      order.add(depPlace);
      order.add(fdPrdtNm);
      order.add(fdSbjt);
      order.add(fdYmd);
      order.add(prdtClNm);
      order.add(rnum);
      
      ArrayList&lt;String&gt; str = new ArrayList&lt;&gt;();
      str.add(&quot;item &gt; atcId&quot;);
      str.add(&quot;item &gt; clrNm&quot;);
      str.add(&quot;item &gt; depPlace&quot;);
      str.add(&quot;item &gt; fdPrdtNm&quot;);
      str.add(&quot;item &gt; fdSbjt&quot;);
      str.add(&quot;item &gt; fdYmd&quot;);
      str.add(&quot;item &gt; prdtClNm&quot;);
      str.add(&quot;item &gt; rnum&quot;);
      
      Iterator&lt;String&gt; iterator = str.iterator(); //Iterator for select
      Iterator&lt;ArrayList&gt; iterator1 = order.iterator(); // Iterator for ArrayList
     
      while (iterator.hasNext()) {
          Document doc = null;   
          try {
              doc = Jsoup.connect(url.toString()).get();
          } catch (Exception e) {
              e.printStackTrace();
          }
          Elements ele = null;
          try {
              ele = doc.select(iterator.next()); 
          }catch(Exception e) {
              e.printStackTrace();
          }
          Iterator&lt;Element&gt; ie1 = ele.iterator();
          ArrayList array = iterator1.next(); // select Array
          while(ie1.hasNext()) {
              array.add(ie1.next().text());
          }
      }
      Connection con = null;
      PreparedStatement pstmt = null;
      String driver = &quot;com.mysql.cj.jdbc.Driver&quot;; // driver
      String sql = &quot;jdbc:mysql://localhost:3306/stuff?useSSL=false&quot;; //mysql url
      String user = &quot;root&quot;; 
      String pw = &quot;rladydals2@&quot;;  
      String SQL = &quot;insert into lost_property(atcId, clrNm, depPlace, fdPrdtNm, fdSbjt, fdYmd, prdtClNm, rnum) values(?, ?, ?, ?, ?, ?, ?, ?)&quot;;
      
      for(int i=0;i&lt;atcId.size();i++) {
          try {
              Class.forName(driver);
              con = DriverManager.getConnection(sql, user, pw);
              pstmt = con.prepareStatement(SQL);
              pstmt.setString(1, atcId.get(i));
              pstmt.setString(2, clrNm.get(i)); 
              pstmt.setString(3, depPlace.get(i)); 
              pstmt.setString(4, fdPrdtNm.get(i)); 
              pstmt.setString(5, fdSbjt.get(i));
              pstmt.setString(6, fdYmd.get(i));
              pstmt.setString(7, prdtClNm.get(i));
              pstmt.setString(8, rnum.get(i));
              int r = pstmt.executeUpdate();
              System.out.println(&quot;row : &quot; + r);
          } catch (SQLException e) {
              e.printStackTrace();
              System.out.println(&quot;[SQL Error : &quot; + e.getMessage() + &quot;]&quot;);
  
          }catch (ClassNotFoundException e1) { 
              e1.printStackTrace();
              System.out.println(&quot;[JDBC Connector Driver error : &quot; + e1.getMessage() + &quot;]&quot;);
          }finally {
              if (pstmt != null) {
                  try {
                      pstmt.close();
                  }catch (SQLException e) {
                      e.printStackTrace();
                  }
              }
              if (con != null) {
                  try {
                       con.close();
                  }catch (SQLException e) {
                      e.printStackTrace();
                  }
              }
          }
      }   
  }
  </code></pre>
  <p>}</p>
  <pre><code>&gt; error
  </code></pre>
  <p>Exception in thread &quot;main&quot; java.lang.IndexOutOfBoundsException: Index 2023 out of bounds for length 2023
  at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
  at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
  at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
  at java.base/java.util.Objects.checkIndex(Objects.java:359)
  at java.base/java.util.ArrayList.get(ArrayList.java:427)
  at practice_1.SQLLostProperty.main(SQLLostProperty.java:101)</p>
  <pre><code></code></pre>