title: Insert JSON Nested Arrays Into MySQL
body: <p>I facing the problem as following. I getting JSON input from user which contains multiple nested arrays and store into MySQL database. The problem is like I am having data with device_id 2, 3 and 4 as in JSON Input below but after execute the JSON in POSTMan using POST method, I only able to store the data of device_id 2, 3 and 4 is unable to save into the database. I tried with other amount of data and it happens the same.</p>
  
  <p>JSON Input:</p>
  
  <pre><code>{
      "app_id":"1",
      "token":"1",
      "device":
      [
          {
              "device_id":"2",
              "setting_id":"2",
              "batch_id":"2",
              "time":"2017-02-07 16:00:00",
              "power":"2"
          },
          {
              "device_id":"3",
              "setting_id":"3",
              "batch_id":"3",
              "time":"2017-02-07 15:00:00",
              "power":"3"
          },
          {
              "device_id":"4",
              "setting_id":"4",
              "batch_id":"4",
              "time":"2017-02-07 14:00:00",
              "power":"4"
          }
      ]
  }
  </code></pre>
  
  <p>Database Code:</p>
  
  <pre><code>public void setSPowerCons(String app_id, String token, ArrayList&lt;PowerConsA&gt; device){
      Connection conn = null;
      PreparedStatement prst = null;
  
      try{
          //Register JDBC driver
          Class.forName(JDBC_DRIVER);
          //Open a connection
          conn = DriverManager.getConnection(DB_URL);
          String SQL = "INSERT INTO powerConsumption"
                  + "(app_id, token, device_id, setting_id, batch_id, time, power)" 
          + "VALUES(?, ?, ?, ?, ?, ?, ?)";
          prst = conn.prepareStatement(SQL);
          //Bind VALUES into parameters
          int j=0;
          prst.setString(1, app_id);
          prst.setString(2, token);
          for(PowerConsA powerconsa : device){
              for(int i=0; i&lt;device.size()-1; i++){
                  prst.setString(3, device.get(i).getDevice_id());
                  prst.setString(4, device.get(i).getSetting_id());
                  prst.setString(5, device.get(i).getBatch_id());
                  prst.setString(6, device.get(i).getTime());
                  prst.setString(7, device.get(i).getPower());
                  prst.addBatch();
              }   
              if(j%1000==0||j==device.size()){
                  prst.executeBatch();
              }
              j++;
          }
          prst.close();
          conn.close();
      }
      catch(Exception e){
          e.printStackTrace();
      }
      finally{
          try{
              if(prst != null){
                  prst.close();
              }
          }
          catch(SQLException sqle){
              sqle.printStackTrace();
          }
          try{
              if(conn != null){
                  conn.close();
              }
          }
          catch(SQLException sqle1){
              sqle1.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Database:
  <a href="https://i.stack.imgur.com/n87Ji.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n87Ji.png" alt="Database"></a></p>
  
  <p>Thanks for everyone that helps for this question and helps pointing out my mistake.</p>