GAMA
GAMA

Reputation: 5996

creating and using java web service to connect remote mysql server

In my android application, I want to create and use java web service to connect to remote mysql server. I tried searching for the same but results are vague.

Can anyone please suggest me how can I do following things:

Is all of the above are possible?

Any article/link/code snippet welcomed.

Edit

So sample web service would be something like this??

HelloWeb.java

@WebService
public class HelloWeb {

    @WebMethod
    public String sayGreeting(String name) {

        return "Greeting " + name + "!";
    }
}

Server.java

public class Server {

    public static void main(String[] args) {

        Endpoint.publish("http://localhost:9898/HelloWeb", new HelloWeb());
        System.out.println("HelloWeb service is ready");
    }
}

Upvotes: 0

Views: 2607

Answers (2)

Maroun Baydoun
Maroun Baydoun

Reputation: 464

You need JDBC to connect to MySQL. You can abstract that by using an ORM, but it would still be using JDBC on a lower level.

You can create a REST web service using JAX-RS from here

Upvotes: 2

duffymo
duffymo

Reputation: 308743

Like all computer science problems, I'd decompose this one into smaller, more manageable pieces:

  1. Create an interface-based service that fulfills your use case.
  2. Expose the interface-based service as a web service, SOAP or REST, to interact with clients via HTTP
  3. Parse, validate, and bind the JSON.
  4. Create an interface-based DAO that uses JDBC to connect to MySQL and perform CRUD operations on the client's behalf.
  5. Inject the DAO into the web service and let it interact with MySQL using JDBC.

You can test each piece independently this way. I think it'll be more reusable, too.

Upvotes: 3

Related Questions