1

I am trying to send data to my firebase database with the Firebase Server SDK (JAVA). I created a service account and initialized firebase like in documentation. https://firebase.google.com/docs/database/server/start

When I start my code, nothing happen. The first time I had a security question from Windows, to accept internet connection. I accepted it. But I have no new data in my firebase database.

I made also a simple app for android with the sdk for android and that works.

Maybe somebody can help me and have some ideas?

FirebaseOptions options = new FirebaseOptions.Builder()
                .setServiceAccount(new FileInputStream("xxxxxxxxxx.json"))
                .setDatabaseUrl("https://xxxxxxxxxx.firebaseio.com/")
                .build();
        FirebaseApp.initializeApp(options);

        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference("message");
        myRef.setValue("www");
Denis Banach
  • 111
  • 1
  • 4
  • 10
  • How are you running this code? Because if it's in a regular JVM, there's a good chance the JVM exits before the write if committed. You can easily test this by adding `Thread.sleep(30000)` at the end. – Frank van Puffelen Aug 09 '16 at 18:29
  • Wow thanks, now it works. I use Thread.sleep(10000); But I don´t understand why this happen so. – Denis Banach Aug 09 '16 at 18:56
  • The write operation (like all interact with Firebase) happens asynchronously. Since the JVM is not aware that there is an outstanding write operation, it exits the program when it has executed the last statement. See http://stackoverflow.com/questions/26671214/i-am-trying-to-use-firebase-to-build-a-backend-for-a-java-desktop-application/27468807#27468807 – Frank van Puffelen Aug 09 '16 at 19:16

0 Answers0