title: How to insert data in a table of a page in Atlassian Confluence using Java
body: <p>I have written a Java program <strong>(using main method only)</strong> for sending HTML content using <strong>JSON</strong>.
  i have some data in my object in separate program which i want to import programmatically in <strong>my page of Atlassian Confluence.</strong>
  Still i am able to insert only static html content and data inside body of my page.
  i never worked before with json.
  how to insert data in row of table.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class Example {
  
   private static final String BASE_URL = "www.example.com";
   private static final String USERNAME = "xxxxx";
   private static final String PASSWORD = "xxxxx";
   private static final String ENCODING = "utf-8";
   
   static HttpResponse putPageResponse;
   static HttpEntity putPageEntity = null;
  
   private static String getContentRestUrl(final Long contentId,
     final String[] expansions) throws UnsupportedEncodingException {
     final String expand = URLEncoder.encode(StringUtils.join(expansions, ","), ENCODING);
    return String
      .format("%s/rest/api/content/%s?expand=%s&amp;os_authType=basic&amp;os_username=%s&amp;os_password=%s",
        BASE_URL, contentId, expand,
        URLEncoder.encode(USERNAME, ENCODING),
        URLEncoder.encode(PASSWORD, ENCODING));
   }
  
   public static void main(final String[] args) throws Exception {
    final long pageId = 00000000;
    HttpClient client = new DefaultHttpClient();
    // Get current page version
    String pageObj = null;
    HttpEntity pageEntity = null;
    try {
     HttpGet getPageRequest = new HttpGet(getContentRestUrl(pageId,
       new String[] { "body.storage", "version", "ancestors" }));
     
     HttpResponse getPageResponse = client.execute(getPageRequest);
     
     pageEntity = getPageResponse.getEntity();
     pageObj = IOUtils.toString(pageEntity.getContent());
    
    } finally {
     if (pageEntity != null) {
      EntityUtils.consume(pageEntity);
     }
    }
  
    // Parse response into JSON
    JSONObject page = new JSONObject(pageObj);
    try {
   
    **page.getJSONObject("body").getJSONObject("storage")
    .put("value","&lt;b&gt;html content here&lt;b&gt;");**
    &lt;!--if i try to write any thing in second param of put() than it replace the all content of body with that.--&gt;
    
    int currentVersion = page.getJSONObject("version").getInt("number");
    page.getJSONObject("version").put("number", currentVersion + 1);
  
    // Send update request
    
     HttpPut putPageRequest = new HttpPut(getContentRestUrl(pageId,
       new String[] {}));
  
     StringEntity entity = new StringEntity(page.toString(),
       ContentType.APPLICATION_JSON);
     putPageRequest.setEntity(entity);
  
     putPageResponse = client.execute(putPageRequest);
     System.out.println("");
     EntityUtils.consume(putPageEntity);
    
     
    } catch(Exception e) {
     System.out.println("exception is: "+e);
    }
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>**
  if any one share any sample code for that that will very helpfull for me.
  i have following table in my page.</p>
  
  <p>__________________________________________|</p>
  
  <p>| S.no     | book title    |  book author    | publish date    |  price<br>
  |_____|________|___________|__________|______|</p>