I have a rest service that retrieves data from a database and returns it to the client. i want the client that is invoking the service to pass parameters to use them in sql query select and display the server output in console. this is what i've managed to do:
@GET
@Path("Result")
@Produces("application/json")
public String getPerson(@QueryParam("nom") String nom, @QueryParam("prenom") String prenom) {
ArrayList <Persons> persons= new ArrayList<Persons>();
Persons person = new Persons();
String query = "Select * from persons where nom=' " + nom + "' and prenom ='" + prenom + "'";
System.out.println(query);
bdcon = new BDConnexion();
try {
conn = BDConnexion.ConnecterBD();
res = bdcon.getResultSet(query, conn);
while (res.next()) {
person.setNom(res.getString(1));
person.setPrenom(res.getString(2));
persons.add(person);
}
} catch (SQLException ex) {
Logger.getLogger(PersonService.class.getName()).log(Level.SEVERE, null, ex);
}
String json = new Gson().toJson(persons);
return json;
}
rest client:
Client client = Client.create();
WebResource webresource = client.resource("http://localhost:8080/PersonServ/rest/Persons/Result")
.queryParam("nom", nom)
.queryParam("prenom",prenom);
ClientResponse response = webresource.accept("application/json").get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
I'm not getting any errors but the client class is not displaying any results. Can anyone help me?
System.out.println(query);prints?