gpt4 book ai didi

java - 查询 Firebase DatabaseReference 的习惯用法是什么?

转载 作者:行者123 更新时间:2023-12-02 02:44:24 27 4
gpt4 key购买 nike

不是 Android 问题。

用于查询数据库的方法:

private void db() throws FileNotFoundException, IOException {
FileInputStream serviceAccount = new FileInputStream("serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl(stringURL)
.build();

log.info(options.toString());

FirebaseApp firebaseApp = FirebaseApp.initializeApp(options);
FirebaseDatabase f = FirebaseDatabase.getInstance(firebaseApp, stringURL);

DatabaseReference databaseNonRoot = f.getReference();
DatabaseReference databaseReference = databaseNonRoot.getRoot();

log.info(databaseReference.toString());

// databaseReference.addValueEventListener(new ValueEventListener(){
//really?
}

我已输入数据manually通过网络界面。如何查询 Firebase?类似于SELECT * FROM <TABLE>的东西这就是我正在寻找的。

JSON数据导出:

{
"abc" : 123,
"bar" : 4342342,
"foo" : 432434
}

另请参阅:

how to get all child list from Firebase android

最佳答案

是的。真的。

databaseReference.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
System.out.println("Key="+childSnapshot.getKey()+" Value="+childSnapshot.getValue());
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
});

请参阅Firebase documentation on dealing with lists了解更多信息。我还建议在这里阅读我的答案:https://stackoverflow.com/a/30943084/209103

关于java - 查询 Firebase DatabaseReference 的习惯用法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44875684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com