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 7710005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:00:18+00:00 2026-06-01T01:00:18+00:00

I have a UI with Create , Update , Delete and Select Operations ,

  • 0

I have a UI with Create , Update , Delete and Select Operations , so for this i thought to design it using Command Pattern

MyServlet

public void doGet(HttpServletRequest req,HttpServletResponse res)
     throws ServletException,IOException
    {

InsertCommand insertCommnd = new InsertCommand();
DeleteCommand deleteCommnd = new DeleteCommand();

// Create the DTO Employee with request parameters and pass it to invoker

if(req.getParameter("action").equals("insert"))

  Invoker invoker = new Invoker();

 invoker.setCommand(insertCommnd );
 invoker.pressButton(emp);


    }

//*Invoker*

public class Invoker
{
    private Command command;

    public void setCommand(Command command)
    {
        this.command = command;
    }


    public void pressButton(Employee emp)
    {
        command.execute(emp);
    }

}

//Command.java

public interface Command
{
public void execute();
}

DeleteCommand.java

public DeleteCommand implements Command
{   

Employee emp;

public DeleteCommand(Employee emp)
{

this.emp = emp;
}

public void execute()
{
// SQL Query to delete Records
}

}

InsertCommand.java

 public InsertCommand implements Command
    {
     Employee emp ;
    public InsertCommand(Employee emp)
    {

    this.emp = emp;
    }

    public void execute()
    {
    // SQL Query to insert Records
    }

    }

Similarly there is a Update Records command

My question is , how can i handle this in case of Select Operations as it returns a ArrayList from Database ?

Also please share your ideas on this design ,as i am new to Designing Software .

  • 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-06-01T01:00:19+00:00Added an answer on June 1, 2026 at 1:00 am

    You are in the right approach meaning that you are trying to use design patterns in your code.
    In your case you are using the wrong pattern.You should be using a DAO pattern instead.

    But saying wrong doesn’t mean that your approach can’t be used.It is just that DAO is the standard for DB.

    In your case your problem is that your execute method returns void and you need a method (extra) that returns a List.

    You could create a second method for select that returns a List and give it a generic name and in your other commands simply throw an UnsupportedMethod exception

    E.g.

    public interface Command 
    { 
    public void execute(); 
    public List fetch();  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to create a database by the following command: mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP, ->
Below is the link How to insert,delete,select,update values in datagridview in C# using MYSQL
Say we have stored procedure(s) performing simple operations like this: CREATE PROCEDURE [dbo].[AddNewAuthorReturnID] (
I create SqlConnection objects in every Insert,Update,Delete and Select methods in asp.net web pages.
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a table trigger like below: CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG BEFORE UPDATE
Can you create websites with Chinese characters in PHP? UPDATE: Perhaps I should have
I have created a Data Access Layer using .NET. Everywhere that I update a
I have the trigger: create or replace TRIGGER JACKET_DELETE BEFORE DELETE ON JACKET FOR
I have an asp.net Formview connected to an SQL datasource. When I create/edit/delete a

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.