So i am working on a java desktop application and what i am looking for is information on how i am going to retrieve information into a jtable from the RESTful API i am using.I have searched through but i did not find anything related to my problem yet. Can i have some guidance on this in order to help me solve my problem? Of course i don't want to be given the solution i just want some feedback on where and what to search for. Thanks! Here's what i have implemented until now
public class Stocks extends javax.swing.JFrame {
public Stocks() {
initComponents();
String url = "http://localhost:8080/service/webresources/test.stocks";
URL obj = null;
try {
obj = new URL(url);
} catch (MalformedURLException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
HttpURLConnection con = null;
try {
con = (HttpURLConnection) obj.openConnection();
} catch (IOException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
try {
// optional default is GET
con.setRequestMethod("GET");
} catch (ProtocolException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
con.setRequestProperty("Accept", "application/json");
StringBuilder response = null;
try (BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()))) {
String inputLine;
response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
} catch (IOException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(response.toString());
} catch (JSONException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
String stockName = "";
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsnObj = null;
try {
jsnObj = (JSONObject) jsonArray.get(i);
} catch (JSONException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
try {
stockName = (String) jsnObj.get("stockName");
} catch (JSONException ex) {
Logger.getLogger(Stocks.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(stockName);
}
}
This is what i have right now, i get the JSON response from the API and for now i print one of the elements of the JSON. How can i convert this response into a table?