I have to perform a query on a DB where since one of the values passed is an array I have used StringUtils.join(array, "','")
Here is how I implemented it, this code is part of the server side of a web-service
public String medico(int age, String sexstr, String etniastr, String[] sintom) {
String tes=StringUtils.join(sintom, "','");
String ris = "no";
String q;
String errore = connetti();
try {
if (errore.equals("")) {
Statement st = conn.createStatement();
//ESECUZIONE QUERY
q = "SELECT DISTINCT nome FROM malattia WHERE eta='" + age + "' AND sesso='" + sexstr + "' AND etnia='" + etniastr + "' AND sintomi IN('tes')";
ResultSet rs = st.executeQuery(q);
if (!rs.last()) {
ris = "no";
} else {
ris = "si";
}
} else {
ris = errore;
}
conn.close();
} catch (Exception e) {
ris = e.toString();
}
return ris;
}
The way i pass tes seems to be the problem, when i pass it the way written it gives me an Error 500(internal server error) when i change it to:
..... sintomi IN('"+tes+"')";
It gives me zero rows,even though the corresponding data exists in the DB
what is the correct way to resolve this issue? Thanks in advance.