3

This is my database:

enter image description here

I am trying to retrieve my data from the firebase database. my execution like : select * from logindb where loginname='pandi' and loginpass='1234'.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my__value);

        mlist = (ListView) findViewById(R.id.mylist);

        Intent intent = getIntent();
        databaseReference = FirebaseDatabase.getInstance().getReference("logindb");

        String search = intent.getStringExtra("mval");

        databaseReference = FirebaseDatabase.getInstance().getReference();

        Query query = databaseReference.child("loginname").orderByChild("loginId").equalTo(search);
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.exists()) {
                    // dataSnapshot is the "issue" node with all children with id 0
                    for (DataSnapshot issue : dataSnapshot.getChildren()) {
                        String address=issue.child("address").getValue().toString();
                        Toast.makeText(getApplicationContext(), address, Toast.LENGTH_SHORT).show();
                    }

                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.d(TAG, "onCancelled: "+databaseError);
            }
        });

No one data is received.

No error was shown here.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Thangapandi
  • 208
  • 2
  • 15

1 Answers1

2

According to your question,

As much i understand you want to search whose username is pandi and password 1234.

Following query might work for you properly.

In this query in if condition it will return the key of node.

Query query = databaseReference.orderByChild("loginname").equalTo(search);
query.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        if (dataSnapshot.exists()) {
            for (DataSnapshot issue : dataSnapshot.getChildren()) {
                LoginPojo pojo = dataSnapshot.getValue(LoginPojo.class);
                if(pojo.getLoginpasssword().equals("1234")){
                    Log.e("Key", issue.getKey());
                }
            }

        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        Log.d(TAG, "onCancelled: "+databaseError);
    }
});
Ashish
  • 6,791
  • 3
  • 26
  • 48
  • Hay buddy, I have this type of comment " Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "loginId"' at loginname to your security and Firebase Database rules for better performance " – Thangapandi Aug 26 '19 at 11:20
  • 1
    This [question](https://stackoverflow.com/questions/45251328/firebase-warning-using-an-unspecified-index) will help you – Ashish Aug 26 '19 at 11:24
  • bro, I am also read this document but I don't know how to retrieve the data from DB. – Thangapandi Aug 26 '19 at 11:33
  • it means you have to add new rule in your realtime database something [like this](https://firebase.google.com/docs/database/security/indexing-data#defining_data_indexes) – Ashish Aug 26 '19 at 11:42