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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:20:42+00:00 2026-06-02T04:20:42+00:00

maybe anybody could help me out. i’m working with Data access object. i have

  • 0

maybe anybody could help me out. i’m working with Data access object.
i have a database:
table Receiverz

num   name
 1    Walmart
 2    Target
 3    McDonalds

i’ve created a class for this table

public class Receiverz {
private int num;
private String name;

public void setNum(int num) {
    this.num = num;
}

public void setName(String name) {
    this.name = name;
}

}

then i created Dao interface and passed a method to it:

public interface Dao {

Receiverz getReceiverz(int num);}

Then i created a class ExpensesDao that implements Dao and created a singleton in it(i aslo set up the connection with database but i will skip that part) and overrode getReceivers(int num) method by making it possible to work with database:

public class ExpensesDao implements Dao {

private static Dao thisdao;
public static synchronized Dao getDao() {
    if (thisdao==null) {
        thisdao = new ExpensesDao();
    }
    return thisdao;
    }

@Override
public Receiverz getReceiverz(int num) {
    Receiverz receiver = new Receiverz();
    try {
        Statement stmt = myConnection.createStatement();
        ResultSet result = stmt.executeQuery("SELECT * FROM receiverz");
        while(result.next()){

            receiver.setNum(num);
            receiver.setName(result.getString(2));

            }

    }
        catch (SQLException e){
             System.out.println(e.getMessage());
         }
    return receiver;

}

when i try to run it in main class:

public class TryDatabase {

public static void main(String[] args) {
    Dao ex = ExpensesDao.getDao(); 
    System.out.println(ex.getReceiverz(2));

all i get is:

listexpenses.Receiverz@193499fd

but i have to get

2 Target

(since i passed 2 in the parameters and it refers to Target in my database.
does anyone know what’s going wrong and what i should change in my code. P.S. i hope i made it clear enough.

  • 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-02T04:20:44+00:00Added an answer on June 2, 2026 at 4:20 am

    ex.getReceiverz(2) is returning a Receiverz object. Thus the System.out.println(ex.getReceiverz(2)); is using the toString() method inherited from java.lang.Object. Create a toString() method in the Receiverz class that will output it the way you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anybody help me to convert the following sql code into procedure? I've read
Maybe here is already such question, but I didn't find it. I have MVVM
Maybe I just don't know .NET well enough yet, but I have yet to
Can anybody help or point me in the right direction for a tutorial/example for
Does anybody know of the reason why could not create instance of UserControl error
I would like to create 10 plots that have different data, but the same
I have a MS Access 2007 report which is based on a query that
I am trying to figure out how to layout my database for a site
There are four high level APIs to access Cassandra and I do not have
can anybody help with the above SourceSafe error? I've spent hours trying to find

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.