I want to push my data (in key:value
pair) into my Realtime Database. This is my code:
DatabaseReference pay_details = database.getReference("pay/0/0/");
pay_details.push(
{
"Actual amount":arr.get(i).get(9),
"Current reading":arr.get(i).get(5),
"Employee":arr.get(i).get(1),
"Expected amount":arr.get(i).get(9),
"Installment":arr.get(i).get(10),
"Meter current date":arr.get(i).get(3),
"Meter previous date":arr.get(i).get(2),
"Previous reading":arr.get(i).get(4),
"Start from":arr.get(i).get(8),
"Total charge":arr.get(i).get(7),
"Type":arr.get(i).get(0),
"Unit consumed":arr.get(i).get(6)
}
);
This is my table structure:
I keep getting multiple syntax errors in the push
section. Where am I going wrong?
2
Answers
The best way to send/store data in real-time database is to create an object of
Hashmap. Below is the code to achieve this objective
The add data to the Realtime Database you need to use setValue() method. In code
If you want to add multiple children, then you can also use push().