private String createAccount(String name, String instanceUrl,
            String accessToken, PrintWriter writer) throws ServletException,
            IOException {
        String accountId = null;

        HttpClient httpclient = new HttpClient();

        JSONObject account = new JSONObject();

        try {
            account.put("Name", name);
        } catch (JSONException e) {
            throw new ServletException(e);
        }

        PostMethod post = new PostMethod(instanceUrl
                + "/services/data/v20.0/sobjects/Account/");

        post.setRequestHeader("Authorization", "OAuth " + accessToken);
        post.setRequestEntity(new StringRequestEntity(account.toString(),
                "application/json", null));

        try {
            httpclient.executeMethod(post);

            writer.write("HTTP status " + post.getStatusCode()
                    + " creating account\n\n");

            if (post.getStatusCode() == HttpStatus.SC_CREATED) {
                try {
                    JSONObject response = new JSONObject(new JSONTokener(
                            new InputStreamReader(
                            post.getResponseBodyAsStream())));
                    System.out.println("Create response: "
                            + response.toString(2));

                    if (response.getBoolean("success")) {
                        accountId = response.getString("id");
                        writer.write("New record id " + accountId + "\n\n");
                    }
                } catch (JSONException e) {
                }
            }
        } finally {
            post.releaseConnection();
        }

        return accountId;
    }