How do I insert data into the database in real time?

Asked

Viewed 48 times

0

I have an application that consumes data from a network server, follows my code:

        conn.setRequestMethod("GET");
        conn.setRequestProperty("Authorization", "Basic " + asB64);
        conn.setRequestProperty("Accept", "application/json");
        conn.setRequestProperty("Access-Control-Allow-Origin", "*");
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP Error code : "
                    + conn.getResponseCode());
        }
        InputStreamReader in = new InputStreamReader(conn.getInputStream());
        BufferedReader br = new BufferedReader(in);

I’ve already created the object with the data and I’m managing it. The problem is that I needed this application to run in real time to be able to save the data once they were consumed in the database.

  • 1

    That is, you want to save the content read on br in the database? If yes, in which table? Which database exactly?

  • 1

    Ah, don’t use the InputStreamReader which does not receive encoding, otherwise you will have encoding problems. Use InputStreamReader in = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8);.

  • You can create a service on your server, which runs x in x seconds by calling the script that inserts the data into the database.

  • @Rodrigo Vaz Any idea where I can get an example?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.