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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:39:38+00:00 2026-06-13T01:39:38+00:00

I created a new bean called client with Id , Name , LastName and

  • 0

I created a new bean called client with Id, Name, LastName and Address fields. I created the model and the view of course. My model returns a list of all the clients. And this one is working fine.

But I need a model where I can select only one specific client filtered by Id. Can anybody tell me what I need to change (besides the SQL statement) inside this model so I get only one client according to filter (id) criteria from SQL?

{
    Connection connection = getDatabaseConnection();
    request.setAttribute("clientList", getClientList(connection));
    closeDatabaseConnection(connection);
}

private ArrayList<Client> getClientList(Connection con)
{
    String sqlstr = "SELECT * FROM Clients";
    PreparedStatement stmt = null;
    ResultSet rs = null;
    ArrayList<Client> clients = new ArrayList<Client>();

    try
    {
        stmt = con.prepareStatement(sqlStr);
        rs = stmt.executeQuery();

        while (rs.next())
        {
            Client client = new Client();
            client.setId(rs.getInt("Id"));
            client.setName(rs.getString("Name"));
            client.setLastName(rs.getString("LastName"));
            client.setAddress(rs.getString("Address"));

            clients.add(client);
        }

        rs.close();
        stmt.close();
    }
    catch (SQLException sqle)
    {
        sqle.printStackTrace();
    }
    finally
    {
        return clients;
    }
}
  • 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-13T01:39:39+00:00Added an answer on June 13, 2026 at 1:39 am

    Well, I guess you already have a class with a method that you invoke to retrieve all the cliets, right?

    Well, now add another method, but this time a method that receives the client Id as parameter:

    public List<Client> getAllClients();
    public Client getClientById(int clientId);
    

    You will need a secondary SQL statement, since the logic in the first one is for retrieving all records. Something like:

    "select clientId, clientName, ... from clients where clientId=?"
    

    Using a JDBC PreparedStatement you can easily replace the ? for the actual parameter being received by your API.

    You can also consider abstracting your mapping strategy so that you can use it for both methods:

    class ClientMapper implements SqlMapper<Client> {
        @Override
        public Client map(ResultSet rs) throws SQLException {
           Client client = new Client();
           client.setId(rs.getInt("Id"));
           client.setName(rs.getString("Name"));
           client.setLastName(rs.getString("LastName"));
           client.setAddress(rs.getString("Address"));
           return client;
        }
    }
    

    You can also have a ClientsMapper that uses this single client mapper to retrieve all clients.

    class ClientsMapper implements SqlMapper<List<Client>>{
       @Override
       public List<Client> map(ResultSet rs){
         List<Client> result = new ArrayList<>();
         ClientMapper mapper = new ClientMapper();
         while(rs.next()){
            result.add(mapper.map(rs));
         }
         return result;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a managed bean called: @ManagedBean(name=configBean) @SessionScoped public class configBean implements Serializable {
I've created new db via phpMyAdmin and while editing db privilages clicked delete localhost
i have one doubt,i have created new project in eclipse with android 2.3.1 and
Lets go from the start Created New Xcode project,opened interface builder dragged one NSButton
I have a new Codeblocks install with mingw32 compiler. Created new c++ console project
i'm using eclipse platform and window builder pro within. I've already created new project
I created a new product type and everything works except the indexing of the
I created a new cordova project on XCODE, I have some files that I
I created a new repository on github. I selected one of the options that
I created a new project, Windows Phone 7.0 Since i wanted the DockPanel, i

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.