Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:40:18+00:00 2026-05-23T14:40:18+00:00

I’m working on a java 2ME app that submit data to mysql database (am

  • 0

I’m working on a java 2ME app that submit data to mysql database (am running PHP as the scripting language), but am having problem to compare string with the result that comes from the server. I want to compare a string that has been print with PHP eg. echo "OK"; with a string String str = "OK" within my java 2ME codes. Can anyone help me with this?
Here are my codes

register.java

public void register() {
        String result = null;
        PostHttp post = new  PostHttp();

        post.setDocument("birth");
        post.setPath("/notification/");

        //Set Parameters
        post.setParameter("firstname", getChildFirstName().getString());
        post.setParameter("middlename", getChildMiddleName().getString());
        post.setParameter("lastname", getChildLastName().getString());
        post.setParameter("gender", getChildGender().getString(getChildGender().getSelectedIndex()));/***************/
        post.setParameter("childDOB", getChildDOB().getDate().toString());/*******************/
        post.setParameter("birthType", getBirthType().getString(getBirthType().getSelectedIndex()));
        post.setParameter("weight", getBornWithWeight().getString());
        post.setParameter("mother_fname", getMotherFirstName().getString());
        post.setParameter("mother_mname", getMotherMiddleName().getString());
        post.setParameter("mother_lname", getMotherLastName().getString());
        post.setParameter("birthPlace", getPlaceOfBirth().getString());
        post.setParameter("residence", getResidence().getString());
        post.setParameter("residence", getResidence().getString());

        result = post.submit();
        String x = "OK";
        if(result.compareTo(x)){
           this.append("Equal Strings"); 
        }else{
       this.append("Not equal"); 
}
    }

PostHttp.java

import java.io.*;
import javax.microedition.io.*;

public class PostHttp {

    private String protocol;
    private String host;
    private String path; //path to the file
    private String document; // controller function
    private String data; // Post Data

    public PostHttp() {
        // Set the defaults
        protocol = "http://";
        host = "localhost/badis/index.php";
        path = "/notification/";
        document = "trial";
        data = "";

    }

    public void setProtocol(String p) {
        protocol = p;
    }

    public void setHost(String h) {
        host = h;
    }

    public void setPath(String p) {
        path = p;
    }

    public void setDocument(String d) {
        document = d;
    }

    public void setParameter(String parameter, String value) {

        if (data.length() > 0) {
            data = data + "&";
        }
        data = data + parameter + "=" + value;
    }

    HttpConnection setupConnection(String uri) throws IOException {
        HttpConnection connection = null;

        connection = (HttpConnection) Connector.open(uri, Connector.READ_WRITE);
        connection.setRequestMethod(HttpConnection.POST);
        connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
        connection.setRequestProperty("Host", host);
        return (connection);
    }

    void sendPostData(HttpConnection connection, String postData) throws IOException {
        OutputStream outputStream = null;

        outputStream = connection.openOutputStream();
        outputStream.write(postData.getBytes());
        outputStream.close();
    }

    String readResult(HttpConnection connection) throws IOException {
        InputStreamReader inputStream;
        String result = "";
        final int arbitraryBufferSize = 100;
        final int endOfData = -1;
        char[] characterBuffer = new char[arbitraryBufferSize];
        int bytesRead;

        inputStream = new InputStreamReader(connection.openInputStream());
        bytesRead = inputStream.read(characterBuffer);
        while (bytesRead != endOfData) {
            result = result + new String(characterBuffer);
            bytesRead = inputStream.read(characterBuffer);
        }
        inputStream.close();
        return (result);
    }

    public String submit() {
        HttpConnection connection;
        String result;

        try {
            connection = setupConnection(protocol + host + path + document);
            sendPostData(connection, data);
            result = readResult(connection);
            connection.close();
        } catch (IOException ioe) {
            result = "IOException!";
        }
        return (result);
    }
}

Result

 Not equal

php script

 public function birth() {
     echo "OK";
}

am using codeigniter 2.0.1, if that helps.

Thanx in advance..
Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:40:19+00:00Added an answer on May 23, 2026 at 2:40 pm

    Lets be absolutely clear about this. If the following is appending “Not equal”:

        String x = "OK";
        if (result.equals(x)) {
           this.append("Equal Strings"); 
        } else{
           this.append("Not equal"); 
        }
    

    it is because result is not equal to “OK”. There can be no doubt about this.

    I suspect that it is one of the following:

    • There is leading or trailing whitespace on the result String; i.e. a space, TAB or CR or NL character that you can’t see when you output the String to the console.

    • Possibly, the first character is an zero (‘0’) character instead of a capital Oh (‘O’).

    • Possibly, the case is different.

    One way to get to the bottom of this is to take the two strings apart and compare them character by character; e.g.

    String s = "OK";
    if (result.equals(x)) {
        this.append("Equal Strings"); 
    } else if (x.length() != result.length()) {
        this.append("Lengths are different");
    } else if (x.charAt(0) != result.charAt(0)) {
        this.append("Character 0 different");
    } else if (x.charAt(1) != result.charAt(1)) {
        this.append("Character 1 different");
    } else {
        this.append("The universe is being swallowed by a giant squid");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.