Question

I'm currently using NetBeans IDE, so I want to host a WebService and consume it via J2ME. Everything goes well (from writing the web service class, deploying the web server, getting the URL for the WSDL, creating the Java ME Web Service Client, then finally calling the methods).

Currently, my WebMethod login() looks like this:

@WebMethod(operationName = "login")
public boolean login(@WebParam(name = "username") String username, @WebParam(name = "password") String password) {
    boolean result = false;
    System.out.println(username + password);

    try {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url + dbName, dbUsername, dbPassword);

        Statement st = conn.createStatement();
        ResultSet res = st.executeQuery("SELECT COUNT(*) FROM Account WHERE Username = "
                + "'" + username + "' AND Password = '" + password + "'");
        res.next();
        int i = res.getInt(1);
        if (i == 1) {
            result = true;
        }

        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

So I go over to my J2ME app, create the Java ME Web Service Client, enter the WSDL for this class, and I write this line of code to call the web service:

FirefighterService service = new FirefighterSerivce_Stub();
try {
    if (service.login("admin", "admin"); {
        System.out.println("success"); }
    else {
        System.out.println("failure"); }
} catch (Exception e) {
    e.printStackTrace();
}

It SHOULD work. I have tested my line of code in a Java console application, and it worked perfectly (connecting to the database, SELECTing, and then printing the result). The result should be "success". But when I call it via the web service, I always get "failure"...

If it helps, I referenced a lot from this tutorial. http://nandokakimoto.wordpress.com/2009/03/15/creating-a-j2me-web-service-client/

Does anyone have any clue as to where I possibly screwed up? :(

Was it helpful?

Solution

It's alright... I forgot to include my driver into my web app. I suck, I know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top