Java working on JSON

Asked

Viewed 85 times

-1

Well, I am starting my studies in java, for this reason I am a little raw in the possibility, in libraries and other qualities that exist in programming JAVA. Inside many doubts I would like to understand if there is any way to catch an object of the type ResultSet which in this case is the return of a query done as follows:

 ResultSet rs_tbl_CONTROLE_SINCRONISMO = con.query("SELECT * FROM DB_EGLISE.tbl_CONTROLE_SINCRONISMO;");

And turn into a JSON format ?

Is there a library that will do this for me ?

  • @Marconi my problem is being because I don’t know which tables can return from my SQL, so through this how should I transform to JSON ?

  • I know which tables but I don’t know which fields will return

  • Fields or data?

  • The data returned

1 answer

1

Then, you will first have to iterate on the Resultset results

while (rs_tbl_CONTROLE_SINCRONISMO.next()) {
}

and each field of the Voce table should pick up knowing the type of data. for example: rs_tbl_CONTROLE_SINCRONISMO.getit("id");

Voce can do this and populate a Java object

after populated the Object there are some libraries that transform Java Object to Json and Json to Java Object, for example Gson https://github.com/google/gson

Browser other questions tagged

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