如何从Firebase数据库获取数据?

时间:2019-03-07 15:06:51

标签: java android firebase firebase-realtime-database

这是我的Firebase数据库。我只想获取“ Intake-Sec”的子名称,例如(CSE,EEE)。不是CSE或EEE的孩子。我该怎么办。

enter image description here

谢谢!

1 个答案:

答案 0 :(得分:1)

要仅获取INSERT INTO client (id, name, surname, surname2, dob, phone, email, address) SELECT DISTINCT NVL(cl_dni, floor(dbms_random.value(10000000,100000000))), cl_name, cl_surn1, cl_surn2, cl_birth, cl_phone, cl_email, cl_address FROM purchases WHERE NOT EXISTS(SELECT id from client WHERE client.id = purchases.cl_dni); CSE,请使用以下代码行:

EEE

该列表将仅包含两个元素,因为它还将被打印在logcat中:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        List<String> list = new ArrayList<>();
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String key = ds.getKey();
            list.add(key);
            Log.d(TAG, key);
        }

        //Do what you need to do with your list
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
    }
};
rootRef.addListenerForSingleValueEvent(valueEventListener);