hi, I am currently on an assignment to create a club membership registration system, which will need to use client-server side code and access to localhost database.

I have done everything, but apparently my Create, Delete, Search and Update function cannot work, and mostly is because they cannot send the object or the sql statement in string to the server side from the client side. The server side can connect to the database (know it through the print function after the connection works).

*client side
public class SearchActionListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            try{     
                Socket socket = new Socket("localhost", 8000);
 
                ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
                DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
                ObjectInputStream fromServer = new ObjectInputStream(socket.getInputStream());
 
                int utarID = Integer.parseInt(txtUtarID.getText());
 
                String sql = "SEARCH * FROM member WHERE utarID = ?;";
 
                ClubMember member = new ClubMember(utarID);
 
                sqlToServer.writeUTF(sql);
                toServer.writeObject(member);
                sqlToServer.flush();
                toServer.flush();
                System.out.println("Search command sent.");
 
                ClubMember member1 = (ClubMember)fromServer.readObject();
 
                txtName.setText(member1.name);
                if(member1.gender.equals("M")){
                    rbMale.setSelected(true);
                }
                else if(member1.gender.equals("F")){
                    rbFemale.setSelected(true);
                }
                txtAddress.setText(member1.address);
                txtPostcode.setText("" + member1.postcode);
                txtCity.setText(member1.city);
                cbState.setSelectedItem(member1.state);
                txtEmail.setText(member1.email);
                txtPhoneNumber.setText(member1.phoneNumber);
                cbCourse.setSelectedItem(member1.course);
                cbYearIntake.setSelectedItem(member1.yearIntake);
                txtYear.setText("" + member1.year);
                txtTrimester.setText("" + member1.trimester);
                cbPosition.setSelectedItem(member1.position);
            }
            catch(Exception ex){
            }
        }
    }
 
    public class CreateActionListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            try{           
                Socket socket = new Socket("localhost", 8000);
 
                ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
                DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
 
                int utarID = Integer.parseInt(txtUtarID.getText());
                String name = txtName.getText();
                String gender;
                if(rbMale.isSelected())
                    gender = rbMale.getText();
                else
                    gender = rbFemale.getText();
                String address = txtAddress.getText();
                int postcode = Integer.parseInt(txtPostcode.getText());
                String city = txtCity.getText();
                String state = "" + cbState.getSelectedItem();
                String email = txtEmail.getText();
                String phoneNumber = txtPhoneNumber.getText();
                String course = "" + cbCourse.getSelectedItem();
                int yearIntake = Integer.parseInt(cbYearIntake.getSelectedItem().toString());
                int year = Integer.parseInt(txtYear.getText());
                int trimester = Integer.parseInt(txtTrimester.getText());
                String yearTrimester = "" + year + "/" + trimester;
                String position = "" + cbPosition.getSelectedItem();
                java.util.Date date = new java.util.Date();
                java.sql.Date joinedDate = new java.sql.Date(date.getDate());
 
                String sql = "INSERT INTO member VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
 
                ClubMember member = new ClubMember(utarID, name, gender, address, postcode, 
                        city, state, email, phoneNumber, course, yearIntake, year, 
                        trimester, position, joinedDate);
 
                String create = "Utar ID: "+utarID+"\nName: "+name+"\nGender: "+gender+"\nAddress: "+address+"\nPostcode: "+postcode+
                        "\nCity: "+city+"\nState: "+state+"\nEmail: "+email+"\nPhoneNumber: "+phoneNumber+
                        "\nCourse: "+course+"\nYear Intake: "+yearIntake+"\nYear/Trimester: "+yearTrimester+"\nPosition: "+position+
                        "\n\nDo you want to register this member?";
 
                int response = JOptionPane.showConfirmDialog(null, create, "Create Confirm", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE);
                if(response == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null, "Member :" + name + " has been created.", "Created", JOptionPane.INFORMATION_MESSAGE);     
                    System.out.println("Sending now.");
                    sqlToServer.writeUTF(sql);
                    toServer.writeObject(member);
                    sqlToServer.flush();
                    toServer.flush();
                    System.out.println("Object member sent.");
                }
            }
            catch(Exception ex){
            }
        }
    }
 
    public class UpdateActionListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            try{
                Socket socket = new Socket("localhost", 8000);
 
                ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
                DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
 
                int utarID = Integer.parseInt(txtUtarID.getText());
                String name = txtName.getText();
                String gender;
                if(rbMale.isSelected())
                    gender = rbMale.getText();
                else
                    gender = rbFemale.getText();
                String address = txtAddress.getText();
                int postcode = Integer.parseInt(txtPostcode.getText());
                String city = txtCity.getText();
                String state = "" + cbState.getSelectedItem();
                String email = txtEmail.getText();
                String phoneNumber = txtPhoneNumber.getText();
                String course = "" + cbCourse.getSelectedItem();
                int yearIntake = Integer.parseInt(cbYearIntake.getSelectedItem().toString());
                int year = Integer.parseInt(txtYear.getText());
                int trimester = Integer.parseInt(txtTrimester.getText());
                String yearTrimester = "" + year + "/" + trimester;
                String position = "" + cbPosition.getSelectedItem();
                java.util.Date date = new java.util.Date();
                java.sql.Date joinedDate = new java.sql.Date(date.getDate());
 
                String sql = "UPDATE member SET utarID=?, name=?, gender=?, address=?, postcode=?, "
                        + "city=?, stateOfCountry=?, email=?, phoneNumber=?, course=?, yearIntake=?, "
                        + "yearOfTrimester=?, trimester=?, currentPosition=?, joinedDate=? WHERE "
                        + "utarID=?;";
 
                ClubMember member = new ClubMember(utarID, name, gender, address, postcode, 
                        city, state, email, phoneNumber, course, yearIntake, year, 
                        trimester, position, joinedDate);
 
                String update = "Utar ID: "+utarID+"\nName: "+name+"\nGender: "+gender+"\nAddress: "+address+"\nPostcode: "+postcode+
                        "\nCity: "+city+"\nState: "+state+"\nEmail: "+email+"\nPhoneNumber: "+phoneNumber+
                        "\nCourse: "+course+"\nYear Intake: "+yearIntake+"\nYear/Trimester: "+yearTrimester+"\nPosition: "+position+
                        "\n\nDo you want to update this member's information?";
                int response = JOptionPane.showConfirmDialog(null, update, "Update Confirm", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE);
                if(response == JOptionPane.YES_OPTION){
                        JOptionPane.showMessageDialog(null, "Member :" + name + " has been Updated.", "Updated", JOptionPane.INFORMATION_MESSAGE);
 
                        sqlToServer.writeUTF(sql);
                        toServer.writeObject(member);
                        sqlToServer.flush();
                        toServer.flush();
                        System.out.println("Object member sent.");
                }
            }
            catch(Exception ex){
            }
        }
    }
 
    public class DeleteActionListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            try{
                Socket socket = new Socket("localhost", 8000);
 
                ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
                DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
 
                int utarID = Integer.parseInt(txtUtarID.getText());
                String name = txtName.getText();
                String delete = "Do you want to delete member: " + name +"?";
 
                String sql = "DELETE FROM member WHERE utarID=?;";
 
                ClubMember member = new ClubMember(utarID);
 
                int response = JOptionPane.showConfirmDialog(null, delete, "Delete Confirm", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE);
                if(response == JOptionPane.YES_OPTION){
                        JOptionPane.showMessageDialog(null, "Member :" + name + " has been deleted.", "Deleted", JOptionPane.INFORMATION_MESSAGE);
 
                        sqlToServer.writeUTF(sql);
                        toServer.writeObject(member);
                        sqlToServer.flush();
                        toServer.flush();
                        System.out.println("Delete statement sent.");
 
                        txtUtarID.setText(null);
                        txtName.setText(null);
                        buttonGroup.clearSelection();
                        txtAddress.setText(null);
                        txtPostcode.setText(null);
                        cbState.setSelectedIndex(0);
                        txtCity.setText(null);
                        txtEmail.setText(null);
                        txtPhoneNumber.setText(null);
                        cbCourse.setSelectedIndex(0);
                        cbYearIntake.setSelectedIndex(0);
                        txtYear.setText(null);
                        txtTrimester.setText(null);
                        cbPosition.setSelectedIndex(0);
                }
            }
            catch(Exception ex){
            }
        }
    }

*server side
public class ServerSideProgram extends JFrame{
    public ServerSideProgram(){     
        setTitle("Server Side Program Book Storage");
        setVisible(true);
        pack();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
 
        try{
            ServerSocket serverSocket = new ServerSocket(2002);
            System.out.println("Server started");
 
            while(true){
                Socket socket = serverSocket.accept();
                System.out.println("Connection received"); 
 
                HandleClient thread = new HandleClient(socket);
                thread.start();
            }
        }
        catch(Exception ex){
        }
    }
 
    public class HandleClient extends Thread{
        private Socket socket;
 
        public HandleClient(Socket socket){
            this.socket=socket;
        }
 
        public void run(){
 
 
            try{
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Driver loaded...\n");
 
                Connection bookDB = DriverManager.getConnection("jdbc:mysql://localhost/book?user=root&password=");
                System.out.println("Student database connnected...\n");
 
                String sql = "INSERT INTO book VALUES (?,?,?,?,?,?,?);";
                PreparedStatement stmtInsert = bookDB.prepareStatement(sql);
 
                ObjectInputStream fromClient = new ObjectInputStream(socket.getInputStream());
                ObjectOutputStream toClient = new ObjectOutputStream(socket.getOutputStream());
 
                while(true){
                    Book book1 = (Book)fromClient.readObject();
                    stmtInsert.setInt(1,book1.id);
                    stmtInsert.setString(1,book1.isbnNo);
                    stmtInsert.setString(1,book1.author);
                    stmtInsert.setString(1,book1.title);
                    stmtInsert.setString(1,book1.publisher);
                    stmtInsert.setString(1,book1.location);
                    stmtInsert.setInt(1,book1.year);
                    stmtInsert.executeUpdate();
                    JOptionPane.showMessageDialog(null, "SUCCESSFULLY INSERTED TO MYSQL TABLE" , "Inserting Data", JOptionPane.INFORMATION_MESSAGE);
                }
            }
            catch(Exception e){
            }
        }
    }
 
    public static void main(String[] args){
            new ServerSideProgram();
    }
}


--- Update ---

Solved, i just changed the way to handle multiple event, by sending an integer value for each button u clicked, then by comparing the value with if-else statement to do it.