json - Working With Java to transform result of ResultSet, by which I do not know the number of columns in the query -
this question has answer here:
- how convert java resultset json? 8 answers
i starting studies in java. reason not familiar libraries , methods exist java. understand if there way of catching object of type resultset, the return of query made follows:
the resultset rs_tbl_control_synchronism = con.query("select * db_eglise.tbl_control_synchronism;");
after obtaining resultset, there way transform output json format? there library, or other method me?
i noticed few question similar none of them respond doubts, must understand how in java transform return of resultset object json, in response found on site, noticed necessary inform each field returned, not know fields return dynamic program, i.e. every time make query. how should proceed through fault ? gson makes ? , how ?
1)firs set class path gson-2.1.jar
2)code conver resultset object information json .
resultset rs_tbl_control_synchronism = con.query("select * db_eglise.tbl_control_synchronism;"); jsonobject jsonresponse = new jsonobject(); jsonarray data = new jsonarray(); while(rs_tbl_control_synchronism.next() ) { jsonarray row = new jsonarray(); row.add(new jsonprimitive(rs_tbl_control_synchronism.getstring("columnname1"))); row.add(new jsonprimitive(rs_tbl_control_synchronism.getstring("columnname2"))); row.add(new jsonprimitive(rs_tbl_control_synchronism.getstring("columnname3"))); data.add(row); } jsonresponse.add("aadata", data);
Comments
Post a Comment