Question

first i couldn't find an answer to this problem, so that's why i'm posting this question.

i have a client-server architecture, both written in java, the server is connected to the client and to a mysql Database, the role of the server is to do the CRUD operations the client need.

Example: if the user in the client clicked on insert a new employee, he will fill the textfield and send the object(employee) to the server so the server can add it to the database.

my question is : how can the server know what operation is needed? how can i modify the sended stream so it can be "add this employee to database".

sorry i'm new to programming, and i can't post code because it's not yet written, thanks in advance.

Was it helpful?

Solution

There are many ways, here 2 from the top of my head.

  1. Write a Command class that contain the type of the command and parameters, than Serialize it and send it to the server <> client.

  2. Choose a Protocol(Language that both of the server and the client will comply) and Serialize it using JSON/XML.

Example: (Not have been tested)

public class Command {

    CommandType _commandType;
    String _param;

    public Command(CommandType commandType, String param)
    {
        setCommandType(commandType);
        setParam(param);
    }

    public CommandType getCommandType() { return _commandType; }
    public void setCommandType(CommandType commandType) { _commandType = commandType; }

    public String getParam() { return _param; }
    public void setParam(String param) { _param = param; }
}

public enum CommandType {
    CREATE_EMPLOYEE, DELETE_EMPLOYEE
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top